Yay that works great i have a slight other problem tho with the same script...

This code should load a MovieClip from the library 5 times, place each on the 
stage and then load a different image into each one, instead it loads the 5 
MovieClips from the library, places them on the stage and then only loads the 
image into the last (5th) MovieClip

!!!! this code will not run as its stripped !!!!


   var itemList:XMLList  = locationInfo.item;

   for (var i = 0; i < itemList.length(); i++) // Loops through 5 times
   {
    _summaryElement[i] = loadLibrary(summaryContainer); // Load our MovieClip 
from the library
    loadImage("images/" + i + ".jpg", _summaryElement[i].sumImg); // Should 
load image into _summaryElement[i].sumImg which is a blank placeholder movieclip
   }

   function loadImage(filename:String, mcName:MovieClip):void
   {
    _mcName = mcName; // Contains MovieClip object (object 1 through 5)

    var imageLoader:Loader = new Loader();
    var imageURL:URLRequest = new URLRequest(filename);

    imageLoader.load (imageURL);
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, 
imgLoadComplete);
    
   }

   function imgLoadComplete(ev:Event):void
   {
    _mcName.addChild(ev.target.content); // This should add the loaded image 
into the placeholder movieclip for each of the 5 MovieClips
   }

SJM
  ----- Original Message ----- 
  From: Rob Romanek 
  To: Flash Coders List 
  Sent: Friday, May 02, 2008 4:23 PM
  Subject: Re: [Flashcoders] [AS3] Problem with For loop


  Try the change I've added below and see if it works for you.


  On 2-May-08, at 10:58 AM, SJM - Flash wrote:

  > This function should loop through 5 times creating 5 different  
  > MovieClips, each one with a mouse click event attached, which should  
  > trace the value of "i" either 1, 2, 3, 4 or 5. So the first  
  > movieclip should output 1, second should output 2 and so on...
  >
  >     for (var i = 0; i < itemList.length(); i++) // itemList.length()  
  > is equal to 5
  >     {
  >      _summaryElement[i] = loadLibrary(itemContainer); // Loads  
  > MovieClip from library
  _summaryElement[i].name = String(i);

  >
  >
  >      trace(i); // Outputs correctly "1... 2... 3... 4... 5..."
  >
  >      var summaryClick = function (ev:Event)
  >      {

  >
  >        //trace(i); // Outputs incorrectly (Outputs "5" on each  
  > MovieClip click) ???
  trace(ev.target.name);

  >
  >      }
  >
  >      addChild(_summaryElement[i]); // Adds MovieClip to stage
  >
  >      _summaryElement[i].addEventListener(MouseEvent.CLICK,  
  > summaryClick); // Adds an click event to each MovieClip
  >     }
  >
  > Thanks
  > SJM
  > _______________________________________________
  > Flashcoders mailing list
  > Flashcoders@chattyfig.figleaf.com
  > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
  _______________________________________________
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to