2012-06-21 25 views
0

我需要從javascript調用flash函數。我使用flash.external和addCallback來做到這一點。萬事都很好,但是當我在Flash中使用的FileReference,功能沒開我的瀏覽器...

爲什麼從JavaScript工作調用Flash函數,但FileReference在閃存中不起作用?

請查看下面describtion:
我打電話給我的功能在JavaScript與此代碼: <input type="button" value="Browse" onclick="sendToFlash('Hello World! from HTML');" /> 可以看到我所有如下HTML:

<html> 
<head> 
<title>Upload test</title> 
</head> 
<script> 
function hello (size) { 
    alert ("size hast: " + size); 
} 

function sendToFlash(val){ 
    var flash = getFlashObject(); 
    flash.new_browser(val); 
} 

var flash_ID = "Movie2"; 
var flash_Obj = null; 
function getFlashObject(){ 
    if (flash_Obj == null){ 
     var flashObj; 
     if (navigator.appName.indexOf("Microsoft") != -1){ 
      flashObj = window[flash_ID]; 
     } 
     else{ 
      flashObj = window.document[flash_ID]; 
     } 
     flash_Obj = flashObj; 
    } 
    return flash_Obj; 
} 
</script> 

    <body> 
    <center> 

    <embed width="560" height="410" type="application/x-shockwave-flash" 
    flashvars="sampleVars=loading vars from HTML" 
    salign="" allowscriptaccess="sameDomain" allowfullscreen="false" menu="true" name="Movie2" 
    bgcolor="#ffffff" devicefont="false" wmode="window" scale="showall" loop="true" play="true" 
    pluginspage="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" 
    quality="high" src="Movie2.swf"> 

    </center> 

    <input type="button" value="Browse" onclick="sendToFlash('Hello World! from HTML');" /> 
    </body> 
</html> 

當我點擊Browse在HTML頁面中,JavaScript調用sendToFlash功能和SendToFlash函數發送我的字符串閃爍(你好世界從HTML!)。
閃光燈我得到這個字符串下面的代碼:

resultsTxtField.text = ""; 
uploadButton.onPress = function() { 
    return browse_file("Hello World! from Flash"); 
} 

import flash.external.*; 
ExternalInterface.addCallback("new_browser", this, browse_file); 


function browse_file (my_test_val) { 
    _root.resultsTxtField.text = "val: " + my_test_val; 
    import flash.net.FileReference; 
    var fileTypes:Array = new Array(); 
    var imageTypes:Object = new Object(); 
    imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)"; 
    imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png"; 
    fileTypes.push(imageTypes); 

    var fileListener:Object = new Object(); 
    var btnListener:Object = new Object(); 
    var fileRef:FileReference = new FileReference(); 
    fileRef.addListener(fileListener); 
    fileRef.browse(fileTypes); 

    fileListener.onCancel = function(file:FileReference):Void 
    { 
     _root.resultsTxtField.text += "File Upload Cancelled\n"; 
    } 

    fileListener.onSelect = function(file:FileReference):Void 
    { 
     _root.resultsTxtField.text += "File Selected: " + file.name + " file size: "+ file.size + " file type: " + file.type; 
     getURL("javascript:hello("+file.size+");"); 
    } 
} 

我只有一個場景,這代碼是這一幕的根。並且我有一個名爲uploadButton的影片剪輯,並且在此示例中只有一個用作按鈕的矩形。
當你點擊被調用的矩形browse_file("Hello World! from Flash");並打開一個瀏覽器,你可以選擇一張照片上傳。
當你點擊browse在html相同的過程中必須做的,但你看到變量發送功能,但browser選擇一張照片沒有再打開。
我嘗試了幾種方法。例如我設置了新的功能,只打開picture browser或設置新的場景或使用gotoAndPlay等,但還有另一個問題。

你可以從下面的鏈接下載我的來源:
http://www.4shared.com/zip/YTB8uJKE/flash_uploader.html
注意:Java語言onclick="sendToFlash('Hello World! from HTML');"不直接開度工作。你必須在本地主機上打開它。

我會非常高興的任何線索。
非常感謝
禮阿米亞

回答

相關問題