How to pass array value from .as to the comboBox of .mxml code?
I am calling a .as script in .mxml code. I have <mx:ComboBox> for which thr dataprovider is an array value coming from the same .as file. How to bind this to combobox?
My both Codes are as follows:
// ActionScript file
import flash.display.*;
import flash.events.*;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import mx.controls.Alert;
private var fr:FileReferenceList;
private var fls:Array;
private function folder():void
{
fr = new FileReferenceList();
fr.browse([new FileFilter("Zip Files", "*.zip")]);
fr.addEventListener(Event.SELECT, listZipFiles);
}
private function listZipFiles(e:Event):void
{
Alert.show("selectHandler: " + fr.fileList.length + " files");
var file:FileReference = new FileReference;
fls = new Array();
for (var i:uint = 0; i < fr.fileList.length; i++)
{
file = FileReference(fr.fileList[i]);
//Alert.show("File Name: " + fr.fileList[i]);
Alert.show("File Name: " + file.name);
fls.push(file);
}
Alert.show("fls: " + fls);
gotoCmboBx(fls);
}
private function gotoCmboBx(arr:Array):Array
{
}
private function getShpFiles(event:MouseEvent):void
{
}
and .mxml code is:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script source="Asset/folder.as" />
<mx:Button x="10" y="10" label="My Button" width="122" height="31" id="myButton" click="folder()"/>
<mx:ComboBox x="10" y="49" id="cbobx" dataProvider="{fls}" ></mx:ComboBox>
</mx:Application>
The Array class is a top level Object and does not implement IEventDispatcher, which is required for binding. Try using an ArrayCollection instead.
Update: To add items to an ArrayCollection you can either use the addItem() method, or you can use the
push()method of the Array that ArrayCollection wraps in the property source. However, whenever you make direct changes to thesourceArray, you need to call the refresh() method.The
addItem()method is preferred.Update 2: mx:ComboBox has a property labelField which determines what field from the items in the
dataProviderto use. In order to display thenameof a FileReference object, the following should do it: