Results 1 to 5 of 5
Thread: how does contentLoaderInfo work
-
May 7th, 2009, 05:13 AM #113Registered User
postshow does contentLoaderInfo work
I'm trying to figure out how contentLoaderInfo works; I'm trying to display 5 images on stage and place them horizontally based on their individual widths. Everything works fine except inside displayImage i remains at 5. Each width traces out correctly, but i stays at 5. What is it about contentLoaderInfo that I'm not understanding?
for (var i:uint= 0; i<5; i++)
{
loader = new Loader();}
var urlReq:String = "images/Photos/imageSm_000" + i + ".jpg";
loader.load(new URLRequest(urlReq));
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, displayImage;
function displayImage(e:Event):void
{trace(e.target.content.width);}
trace(i);
addChild(e.target.content);
e.target.content.x = 40 + i * e.target.content.width;
Thanks
-
May 7th, 2009, 05:18 AM #2238Registered User
postsevery time you declare the function displayImage, you overwrite the existing copy...so after i has iterated 5 times, the last overwritten version of displayImage has i set to 5.
change your addeventlistener to:
and move function displayImage out of the for loop, and rewrite it like this:Code:loader.contentLoaderInfo.addEventListener(Event.COMPLETE, displayImage(i);
Code:function displayImage(i:uint):Function { return function(e:event):void{trace(e.target.content.width); trace(i); addChild(e.target.content); e.target.content.x = 40 + i * e.target.content.width; }}
-
May 8th, 2009, 05:09 AM #313Registered User
postsThe function traces out in an odd way
Thanks, sebrofm
I appreciate the help, but when I run this and trace out (i, e.target.content.width) I get
4 133
2 77
3 65
1 77
0 77
which makes it difficult to place the images predictably. The sequence matches up (that is, the fourth image is 133 pixels, etc) but the order is not useful.
Thanks again
-
May 9th, 2009, 07:58 AM #413Registered User
postsIn talking to another developer who is just learning as3, his guess is that the order is determined by when loaded was complete, not the order I specified. I thought that's what the contentLoaderInfo did, that is, wait until the first item loaded before proceeding onto the next item.
-
May 9th, 2009, 09:19 AM #5
it has nothing to do with contentLoaderInfo, but your loop. See:
http://www.senocular.com/flash/tutor...#loopfunctions

Reply With Quote




Bookmarks