将数组值从 .as 脚本传递到 .mxml 代码的组合框
如何将.as中的array
值传递到.mxml代码的comboBox
?
我正在 .mxml 代码中调用 .as 脚本。我有
,其中 thr dataprovider 是来自同一个 .as 文件的 array
值。如何将其绑定到组合框?
我的两个代码如下:
// 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
{
}
.mxml 代码是:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Array 类是顶级对象,不实现 IEventDispatcher,其中需要进行绑定。尝试使用 ArrayCollection 代替。
更新:要将项目添加到 ArrayCollection,您可以使用 addItem() 方法,或者您可以使用 Array 的
push()
方法ArrayCollection 包含在属性 source。但是,每当您直接更改source
数组时,都需要调用refresh() 方法。首选
addItem()
方法。更新 2: mx:ComboBox 有一个属性 labelField 确定使用
dataProvider
中项目的哪个字段。为了显示 FileReference 对象的名称
,应执行以下操作: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 thesource
Array, 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
dataProvider
to use. In order to display thename
of a FileReference object, the following should do it: