1 Reply Latest reply on May 9, 2011 7:29 AM by nikos101

    Is there a way to generate Image Containers using script?

    kevc0722

      I'm quite new to flex and have looked in to this question all over the place but I think I'm not looking in the right direction.

      I'm writing something with a bunch of Image Containers on top of each other, so I can distribute jpg images from an array to each one and control it's alpha.

       

      The script:

                              var urlArray:Array = new Array(20);
                              for (var i:int = 0; i <= 19; i++)
                              {   
                                  var n:int = i+1;
                                 
                                  urlArray[i] = new Loader();
                                  urlArray[i].load(new URLRequest(picUrl + n + ".jpg"));                           
                                  this["myImage" + n].addChild( urlArray[i] );
                                 
                                  if (i == 19)
                                  {
                                      urlArray[19].contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadingComplete);
                                  }                                                   
                              }

       

      The containers:

              <mx:Image id="myImage1" alpha="0" x="0" y="0"/>
              <mx:Image id="myImage2" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage3" alpha="0" x="0" y="0"/>
              <mx:Image id="myImage4" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage5" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage6" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage7" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage8" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage9" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage10" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage11" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage12" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage13" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage14" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage15" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage16" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage17" alpha="0" x="0" y="0"/>
              <mx:Image id="myImage18" alpha="0" x="0" y="0"/> 
              <mx:Image id="myImage19" alpha="0" x="0" y="0"/>
              <mx:Image id="myImage20" alpha="0" x="0" y="0"/>

       

      Is there a way to generate these <mx:Image> containers dynamically using a script so the code doesn't look so bulky.

      Any help is greatly appreciated, thanks in advance