-
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);
}
}
}
}
-
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.
-
Thanks! Will try that
-
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.COMPLETE, onDataLoaded);
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 = 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); if(i<web_thumbs.image.length()){ 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); i++ } } } }
Last edited by mgason; 11-29-2009 at 04:26 PM.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|