why call flash function from javascript work but FileReference don't work in flash?

ultrasbuli

New Member
I need call flash function from javascript. I use flash.external and addCallback to do this. all things work well but when I use FileReference in my flash, function did not open my browser ...

please see below describtion:
I call my function in javascript with this code:\[code\]<input type="button" value="http://stackoverflow.com/questions/11144334/Browse" onclick="sendToFlash('Hello World! from HTML');" />\[/code\]you can see all my HTML as below:
\[code\]<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="http://stackoverflow.com/questions/11144334/Movie2.swf"> </center> <input type="button" value="http://stackoverflow.com/questions/11144334/Browse" onclick="sendToFlash('Hello World! from HTML');" /> </body></html>\[/code\]when I click \[code\]Browse\[/code\] in html page, javascript call sendToFlash function and \[code\]SendToFlash\[/code\] function send my string (Hello World! from HTML) to flash.
in flash I get this string with below code:
\[code\]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+");"); }}\[/code\]I have only one Scene and this code is on root of this Scene. and I have one movie clip named \[code\]uploadButton\[/code\] and has only a rectangle that work as button in this sample.
when you click on rectangle \[code\]browse_file("Hello World! from Flash");\[/code\] called and a browser open that you can select a photo to upload.
when you click on \[code\]browse\[/code\] in html same process must do but as you see variable send to function but \[code\]browser\[/code\] to select a photo did not open any more.
I try several ways. for example I set new function to open only \[code\]picture browser\[/code\] or set new Scene or use gotoAndPlay and more but there is another problem.

you can download my source from below link:
http://www.4shared.com/zip/YTB8uJKE/flash_uploader.html
note that javascript \[code\]onclick="sendToFlash('Hello World! from HTML');"\[/code\] don't work in direct opening. you must open it in localhost.

I'll be so so happy for any clue.
thanks so much
Reza Amya
 
Top