4 Replies Latest reply on Oct 5, 2010 2:34 PM by leonapster

    Create dinamic component

    napster3000

      i want to create as many image component as many are in an array

       

      For example

       

      private var data:ArrayCollection = new ArrayCollection();

      data[0] = "pic0.jpg";

      data[1] = "pic1.jpg";

      data[2] = "pic2.jpg";

      data[3] = "pic3.jpg";

      data[4] = "pic4.jpg";

       

       

      in this case i want to create 5 image component with their source image.

       

      how do?

        • 1. Re: Create dinamic component
          Flex harUI Adobe Employee

          You could have a List of Images or use mx:Repeater or just create them in a

          loop and add them to a container.

          • 2. Re: Create dinamic component
            BhaskerChari Level 4

            Hi napster,

             

            As suggested by Alex you can try the below approaches...

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:Application

             

             

            xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

             

             

            <mx:Script>

            <![CDATA[

             

             

            import mx.collections.ArrayCollection;

             

            [

            Bindable]private var _data:ArrayCollection = new ArrayCollection(["pic0.jpg","pic1.jpg","pic2.jpg","pic3.jpg","pic4.jpg","pic5.jpg"]);

             

             

            ]]>

             

            </mx:Script>

             

             

             

            <mx:VBox verticalGap="0">

             

             

            <mx:Repeater id="rptImages" recycleChildren="true" dataProvider="{_data}">

             

             

            <mx:Image source="{rptImages.currentItem}" />

             

             

            </mx:Repeater>

             

             

            </mx:VBox>

             

             

             

            <mx:List id="lstImages" dataProvider="{_data}">

             

             

            <mx:itemRenderer>

             

             

            <mx:Component>

             

             

            <mx:Image source="{data}"/>

             

            </mx:Component>

             

            </mx:itemRenderer>

             

            </mx:List>

            </mx:Application>

             

             

            You can use either use a Repeater component or a List control as shown in the above example.

             

             

             

            Thanks,

            Bhasker

            • 3. Re: Create dinamic component
              leonapster

              Ok, great!

              And if i want to access data of a XML return?

               

              For example

               

              my arrayCollection will be

              data[id] = 11;

              data[image] = "pic.jpg";

              data[name] = "example pic";

               

              data[id] = 12;

              data[image] = "pic1.jpg";

              data[name] = "example pic1";

               

               

              how access to image?

               

              I tried this

               

              <mx:Image  source="rptImages.CurrentItem.image" />

               

               

              but doesn't work

              • 4. Re: Create dinamic component
                leonapster Level 1

                ok, sorry! Now it works!!

                 

                thank you very much!!;)