6 Replies Latest reply on Oct 17, 2007 12:59 AM by peewee64

    array value

    FlexPrashant
      i have 42 labels like lbl11,lbl12........17
      lbl21.........lbl27

      i want to create a array in which i can store the value of label like this

      array[1][1]=lbl11.text
      array[1][2]=lbl12.text

      how do it possible in flex or action script
      please help me Huh
        • 1. Re: array value
          Gregory Lafrance Level 6
          This code may help:
          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
          <mx:Script>
          <![CDATA[
          [Bindable]
          private var arr:Array = new Array();
          public function init():void {
          arr.push(lbl1.text);
          arr.push(lbl2.text);
          }
          ]]>
          </mx:Script>

          <mx:Label id="lbl1" text="Label1"/>
          <mx:Label id="lbl2" text="Label2"/>
          <mx:List id="cb1" dataProvider="{arr}"/>

          </mx:Application>
          • 2. Re: array value
            FlexPrashant Level 1
            thanks dear Greg Lafrance
            But i want to push the array values like ::::::::::-------

            function push_arr(lbl:Label)
            {
            int x= substring lbl.id(3,4)
            int 4= substring lbl.id(4,5)
            array[x][y].push=lbl.text;
            Alert.show(array[x][y])
            }

            Is it possible in flex 2 with action script
            if yes plz plz help me




            • 3. Re: array value
              atta707 Level 2
              would this help?

              var arr1:Array = new Array();
              var arr2:Array = new Array();

              var children:Array = this.getChildren();

              for each(var child:UIComponent in children) {
              var label:Label = child as Label;
              if (label && label.id.substr(0, 3) == 'lbl1') {
              arr1.push(label.text);
              }
              else if (label && label.id.substr(0, 3) == 'lbl2') {
              arr2.push(label.text);
              }

              }
              • 4. Re: array value
                peewee64
                I think, you mean something like this:

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;
                var labels : Array = new Array();
                function pushArray(myLabel : Label){
                var x = myLabel.id.substr(3,1);
                var y = myLabel.id.substr(4,1);
                var tmp: Array = labels[x] == null ? [] : labels [x];
                tmp[y] = myLabel.text;
                labels[x] = tmp;
                Alert.show(labels[x][y]);
                }
                ]]>
                </mx:Script>
                <mx:Label id="lbl12" text="Hallo Welt!" />
                <mx:Button label="click" click="pushArray(lbl12);" />
                </mx:Application>

                Allthough, I would prefer an assoziative one like that:

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;
                var labels : Object = new Object();
                function pushArray(myLabel : Label){
                labels[myLabel.id]=myLabel.text;
                Alert.show(labels[myLabel.id]);
                }
                ]]>
                </mx:Script>
                <mx:Label id="lbl12" text="Hallo Welt!" />
                <mx:Button label="click" click="pushArray(lbl12);" />
                </mx:Application>

                I hope, this will help!
                • 5. Re: array value
                  FlexPrashant Level 1
                  thanks dear but actually i am calling this function on label's click and i am checking that on clicking of a lable the value of a particular label is equal to or not with others label okay that is why i am storing the value of each label in array and i have to store it as the id of label then i will compare it and i am storing the label text according to it's id like if label id is lbl12
                  then value must be store in the array [1][2] position and if it is lbl62 value must store in array [6[2]
                  is it possible like C,C++
                  x=value of 1st integer in label id
                  y= value of 2nd integer in label id
                  then array [x][y]=lbl.text
                  this label will pass when the function will call on label click

                  ok please help me

                  • 6. Re: array value
                    peewee64 Level 1
                    >like if label id is lbl12
                    >then value must be store in the array [1][2] position and if it is lbl62 value must store in array [6[2]
                    >is it possible like C,C++
                    >x=value of 1st integer in label id
                    >y= value of 2nd integer in label id
                    >then array [x][y]=lbl.text
                    Sorry, but I thought, that this is exactly that, what the first of my code examples did. Storing the values in an array of arrays, you get a multidimensional array, where you can get the values (property text) with the integers of the label id with x being the 1st and y being the second number of the id, so let me know, why it does not fit your needs.