A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: loading array elements into holder clips

  1. #1
    Senior Member
    Join Date
    Nov 2003
    Posts
    385

    loading array elements into holder clips

    I am trying to load an array of web_thumbs into an array of thumb "holders" I've got the holders loading in a grid but then the way I have it, all of the web_thumbs load into each of the holders instead of one web_thumb per holder - I've tried it every which way and this is as close as I can get it without help... Can someone tell me what i need to do to have one web_thumb load into each thumb holder? This is what i have in place:

    var dataLoader:URLLoader = new URLLoader();
    dataLoader.load(new URLRequest("web_thumbs.xml"));
    dataLoader.addEventListener(Event.COMPLETE, onDataLoaded);

    var web_thumbs:XML;

    function onDataLoaded(evt:Event):void {
    web_thumbs=new XML(dataLoader.data);
    setupThumbs();
    }

    function setupThumbs() {
    var rows:int=3;
    var cols:int=4;
    for (var py:int = 0; py <rows; py++) {
    for (var px:int = 0; px <cols; px++) {
    var thumb:MovieClip = new Thumb();
    thumb.x=140+(thumb.width*px);
    thumb.y=100+(thumb.height*py);
    addChild(thumb);
    for (var i:int = 0; i<web_thumbs.image.length(); i++) {
    var image:Loader = new Loader();
    thumb.addChild(image);
    image.load(new URLRequest(web_thumbs.image[i].@source));
    image.x = image.x-(thumb.width/2);
    image.y = image.y-(thumb.height/2);
    }
    }
    }
    }

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You need to remove the innermost loop and use the row and column vars to determine which image index to load. Or just use a counter which is incremented in the inner (col) loop.

  3. #3
    Senior Member
    Join Date
    Nov 2003
    Posts
    385
    Thanks! Will try that

  4. #4
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    you are looping the whole image list every time you add a thumb, thus adding them all every time.

    maybe something like this?
    PHP Code:
    var dataLoader:URLLoader = new URLLoader();
    dataLoader.load(new URLRequest("web_thumbs.xml"));
    dataLoader.addEventListener(Event.COMPLETEonDataLoaded);

    var 
    web_thumbs:XML;

    function 
    onDataLoaded(evt:Event):void {
    web_thumbs=new XML(dataLoader.data);
    setupThumbs();
    }

    function 
    setupThumbs() {
    var 
    i:int 0;
    var 
    rows:int=3;
    var 
    cols:int=4;
    for (var 
    py:int 0py <rowspy++) {
    for (var 
    px:int 0px <colspx++) {
    var 
    thumb:MovieClip = new Thumb();
    thumb.x=140+(thumb.width*px);
    thumb.y=100+(thumb.height*py);
    addChild(thumb);
    if(
    i<web_thumbs.image.length()){
        var 
    image:Loader = new Loader();
        
    thumb.addChild(image);
        
    image.load(new URLRequest(web_thumbs.image[i].@source));
        
    image.image.x-(thumb.width/2);
        
    image.image.y-(thumb.height/2);
        
    i++
    }
    }
    }

    Last edited by mgason; 11-29-2009 at 04:26 PM.

  5. #5
    Senior Member
    Join Date
    Nov 2003
    Posts
    385
    Brilliant! Thank You!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center