2 Replies Latest reply on Apr 23, 2010 12:40 AM by pgpradeep

    Is it possible to create an array of labels programmatically?

    pgpradeep Level 1

      Is it possible to have an array of labels, or programmatically create label names (ie label01, label02 etc.)?

        • 1. Re: Is it possible to create an array of labels programmatically?
          David_F57 Level 5

          hi,

           

          this should do the trick

           

          David.

           

           

          <?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="application1_creationCompleteHandler(event)">

          <fx:Script>

          <![CDATA[

          import mx.collections.ArrayCollection;

          import mx.events.FlexEvent;

           

          import spark.components.Label;

           

          private var labelCollection:ArrayCollection = new ArrayCollection(["First", "Second", "Third", "Last"]);

           

          protected function application1_creationCompleteHandler(event:FlexEvent):void

          {

          for (var i:Number =0; i < labelCollection.length; i++)

          {

          var lbl:Label = new Label();

          lbl.id = "lbl_"+String(i);

          lbl.text = labelCollection[i];

          lbl.width = 100;

          labelbar.addElement(lbl);

          }

          }

           

          ]]>

           

          </fx:Script>

          <s:HGroup id="labelbar"/>

          </s:Application>

          • 2. Re: Is it possible to create an array of labels programmatically?
            pgpradeep Level 1

            In my app, Im using viewStacks and canvases to render different views for

            the same mxml.

            I want to change the text dynamically(at a later stage, from a different canvas) once the labels are created.

            How do I get a handle to the labels then?

            "lbl_"+String(i) as Label isnt working.

             

            Thanks,

            Pradeep.