This is the AS3 part:
import flash.net.FileReference;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.system.Security;
Security.allowDomain( "*" );
// file reference:
var file:FileReference = new FileReference();
ExternalInterface.addCallback( "bFile" , choose );
function choose():void{
ExternalInterface.call( "alert( 'browse' )" );
file.browse();
}
HTML part:
<object width="1px" height="1px">
<param name="movie" value="./ftest/uploader.swf">
<embed width="1px" height="1px" allowscriptaccess="always" id="uploader" src="./ftest/uploader.swf">
</object>
JS part:
$( "#uploader" )[ 0 ].bFile();
UPDATE: – [ The action called via clicking on a button ]
$( "#uploader" )[ 0 ] returns the object (just as if I used getElementById).
When triggered, alert is thrown with “broswe” in it, therefore, I know choose() is called.
But it gets no further.
I get these lines in every browser’s console: Uncaught Error: Error calling method on NPObject.
Could you help me figure out what is wrong here?
Believe your problem is security related, the browse method must be called in direct response to a user interaction (KeyboardEvent or MouseEvent). Read the specific detailed section in the docs about this:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#browse()
The part from the docs I’m referencing:
In Flash Player 10 and Flash Player 9 Update 5, you can only call this method successfully in response to a user event (for example, in an event handler for a mouse click or keypress event). Otherwise, calling this method results in Flash Player throwing an Error exception.