flash filereference select event not firing after using browse() and after selecting a file
This is the first time i am working in action script. I have seen a flash programmer working with it. since i know javascript i was able to work in action script.
I am creating a file upload component for my php projects. Until now i have advanced to show the file dialog box using the FileReference api. The select event is not fi开发者_JAVA技巧ring for me. and i did not get any error.
import fl.controls.Button;
import flash.events.*
import flash.net.FileReference
var fr:FileReference = new FileReference();
fr.addEventListener(Event.SELECT,sico);
var myButton:Button = new Button();
addChild(myButton);
myButton.label = "Click Me";
myButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent)
{
myButton.label = "clicked";
fr.browse();
trace('clicked');
})
function sico(event:Event):void
{
//var file:FileReference = FileReference(e.target);
myButton.label = "selected";
trace('selected');
//trace("progressHandler: name=" + file.name + " bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
}
The documentation said that file references should be called only during an event like mouse or keyboard.
what am i missing in the above code?
The example you posted works in Flash CS5 and Flash Player 10.3 which means the problem is not with the code.
Other potential causes of the issue could be:
- The version of Flash Player which you are using is too old. FileReference requires Flash Player 9 or better. Right-click on the Flash Player or use
trace(Capabilities.version)
to see the version number. - Another part of the application is using a FileReference method (eg: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save()). Flash player 10+ allows only one file operation at a time.
- If you are using a Mac, then FileReference may only dispatch the SELECT event when the SWF is run inside of a browser.
IT was like as stated by user:lukevanin in the comment section of his answer. and me too found the same. The problem was i had many frames in the timeline. since i was new to action script while toggling between F9 i was trying F5 so it created frames and it was looping continuously between that.
精彩评论