Spark List Control和DataProvider

时间:2013-01-30 20:06:18

标签: actionscript-3

我很难过。我试图从随机数生成器填充火花列表控件。我可以将随机数添加到我在spark列表声明中指定为我的dataProvider的arrayList中。但是该列表中没有随机数字!不确定我做错了什么,你的帮助表示赞赏。谢谢!

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 

               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>


    <fx:Script>
        <![CDATA[

            import flash.events.MouseEvent;

            import mx.collections.ArrayCollection;
            import mx.collections.ArrayList;
            import mx.core.DragSource;
            import mx.events.DragEvent;
            import mx.managers.DragManager;

        //  [Bindable]
            //public var num1:String;

            [Bindable]
            public var arrayList:ArrayList = new ArrayList();


            var maxNum: Number;
            var minNum: Number;

            function RandomNumber(minNum: Number, maxNum:Number): Number {

                return (Math.floor(Math.random() * (maxNum - minNum +1)) + minNum);}

            protected function h_slider_changeHandler(event:Event):void
            {
                // TODO Auto-generated method stub
                main_number.text = (h_slider.value.toString());
                number_1.text = String(RandomNumber(0,100));
                number_2.text = String(RandomNumber(0,100));
                number_3.text = String(RandomNumber(0,100));
                number_4.text = String(RandomNumber(0,100));

                var num1 = String(number_1.text);


                 var arrayList:ArrayList = new ArrayList([{numberone:num1}]);




            }

        ]]>
    </fx:Script>

    <s:Panel x="49" y="30" width="866" height="541">
        <s:controlBarContent/>



        <mx:HBox id="myHB">
        </mx:HBox>


        <s:TextArea id="number_1" x="56" y="10" width="74" height="74" />
        <s:TextArea id="number_2" x="56" y="387" width="74" height="74"/>
        <s:TextArea id="number_4" x="694" y="10" width="74" height="74"/>
        <s:TextArea id="number_3" x="703" y="387" width="74" height="74"/>
        <s:TextArea id="main_number" x="338" y="97"/>

        <s:TextArea id="drag_to_1" x="194" y="97" width="78" height="80" />
        <s:TextArea id="drag_to_2" x="194" y="284" width="78" height="80"/>
        <s:TextArea id="drag_to_3" x="568" y="97" width="78" height="80"/>
        <s:TextArea id="drag_to_4" x="568" y="284" width="78" height="80"/>
        <s:TextArea x="337" y="298" height="66"/>



        <s:HSlider id="h_slider" x="243" y="434" width="403" height="14"
                   change="h_slider_changeHandler(event)" maximum="100" minimum="0"
                   value="100"/>

        <s:List id="List1" x="56" y="181" width="110" height="92" dataProvider="{arrayList}"
                 dragEnabled="true" labelField="numberone" >

        </s:List>

    </s:Panel>
</s:Application>

2 个答案:

答案 0 :(得分:0)

您有两个永远不会初始化的变量:

var maxNum: Number;
var minNum: Number;

这些变量与RandomNumber函数中的变量具有相同的名称,并且您不在函数外使用它们,因此您应该删除这两行。

答案 1 :(得分:0)

与@ Gunther的观察相似,您对arrayList

的分配
var arrayList:ArrayList = new ArrayList([{numberone:num1}]);

创建一个新的局部变量,并且不分配arrayList实例变量(绑定到列表的变量)。