Search code examples
actionscript-3apache-flexeventsairfilereferencelist

FileReferenceList doesn't fire events


SELECT and CANCEL events are not fired, I did it in a new project to make sure that the problem didn't came from another part of my code.

"Event Fired" never appears in the output when I click on "Open" after selecting files with FileReferenceList.Browsing Dialog. I also tried FileReference and it didn't work. Other events for other elements works (like addedToStage, Click, touch, etc). I am using an Air AS3 Projector project on FlashDevelop with Air 14 and Flex 4.6.0.

This is Main.as :

public class Main extends Sprite 
{
    public function Main():void 
    {
        var asd:FileReferenceList = new FileReferenceList();
        asd.addEventListener(Event.SELECT, traceResult);
        asd.browse();

        trace("FileReferenceList is browsing...");
    }

    public function traceResult(e:Event):void
    {
        trace("Event Fired");
    }
}

application.mxml :

<?xml version="1.0" encoding="utf-8" ?> 
<application xmlns="http://ns.adobe.com/air/application/14.0">

<id>FileReferenceListTest</id> 
<versionNumber>1.0</versionNumber> 
<filename>FileReferenceListTest</filename> 

<name>FileReferenceListTest</name> 
<description></description> 
<copyright></copyright> 

<initialWindow> 
    <title>FileReferenceListTest</title> 
    <content>FileReferenceListTest.swf</content> 
    <systemChrome>standard</systemChrome> 
    <transparent>false</transparent> 
    <visible>true</visible> 
    <minimizable>true</minimizable> 
    <maximizable>true</maximizable> 
    <resizable>true</resizable> 
</initialWindow> 

</application>

In SetupSDK.bat the SDK I am using is : FlashDevelop\Apps\flexairsdk\4.6.0+14.0.0

Capabilities version is : WIN 14,0,0,176 (as asked in another question like this one). I am new with flash, so if your answers contains compiler changes or stuff not easy to find (or check) be precise on how to do it. Thanks for your time :).


Solution

  • After reading carefully the actionScript® 3.0 Reference I saw this :

    Note: In Adobe AIR, the File class, which extends the FileReference class, provides more capabilities and has less security restrictions than the FileReference class.

    So here is the good code:

    public class Main extends Sprite 
    {
        public function Main():void 
        {
            var f:File = new File();
            f.addEventListener("selectMultiple", traceResult);
            f.browseForOpenMultiple("Browse...");
    
            trace("FileReferenceList is browsing...");
        }
    
        public function traceResult(e:Event):void
        {
            trace("Event Fired");
        }
    }