将数组值从 .as 脚本传递到 .mxml 代码的组合框

发布于 2024-11-29 18:29:12 字数 2078 浏览 2 评论 0 原文

如何将.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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上的星空 2024-12-06 18:29:12

Array 类是顶级对象,不实现 IEventDispatcher,其中需要进行绑定。尝试使用 ArrayCollection 代替。

更新:要将项目添加到 ArrayCollection,您可以使用 addItem() 方法,或者您可以使用 Array 的 push() 方法ArrayCollection 包含在属性 source。但是,每当您直接更改 source 数组时,都需要调用refresh() 方法。

myArr.source.push(myFileReference);
myArr.refresh();

首选 addItem() 方法。

更新 2: mx:ComboBox 有一个属性 labelField 确定使用 dataProvider 中项目的哪个字段。为了显示 FileReference 对象的名称,应执行以下操作:

<mx:ComboBox dataProvider="{fls}" labelField="name"/>

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 the source Array, you need to call the refresh() method.

myArr.source.push(myFileReference);
myArr.refresh();

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 the name of a FileReference object, the following should do it:

<mx:ComboBox dataProvider="{fls}" labelField="name"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文