Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Dcoo

How to trace the number of images loaded using loadermax xml image loader

Recommended Posts

I need the number of images loaded so I can calculate the length of the parent imageholder holder the will be pushed to. I have tried all kinds of ways of tracing.

trace(event.target.content as XML )
race((event.target.content as XML).data.LoaderMax.ImageLoader.length())
trace((event.target.content as XML).data.LoaderMax.children().length())

his gave me a series of "null"s, but they do match the correct number of images loaded.

how can I get a number ? and can I pass that number  ?

 

function imageCompleteHandler(event:LoaderEvent):void
{


var loadedImage:ContentDisplay = event.target.content as ContentDisplay;
loadedImage.alpha = 0;


trace(event.target.content  as XML )


{


TweenLite.to(loadedImage, 5, {alpha:1});
};


galleryArr.push(loadedImage);

}
Link to post
Share on other sites

Since you are pushing each loadedImage into an array, you could just get the length of that array, right?

 

I suppose you could create your own variable that you increment whenever imageLoaded runs, but that doesn't seem necessary considering the previous suggestion.

 

If you want to stick strictly to the LoaderMax API you could call LoaderMax's getChildren() method which will then return an Array of child loaders. You could then loop through each loader and check its status, you could then count each loader that has a status of LoaderStatus.COMPLETED. Again, probably too much work.

 

If you need something different, please feel free to share a simple example of your working project with minimal assets (1 fla, 2 images, 1 xml file or similar configuration) so that we can bette assess a solution.

Link to post
Share on other sites
Since you are pushing each loadedImage into an array, you could just get the length of that array, right?

 

yes this works well! thank you!

what Im trying to do it calculate the width of the parent mc after I pushed the my images into it. and I'm loading from dynamic folder so the number of images changes

I used trace(galleryArr.length ); it gives me a number of images loaded and each image is 400px wide so now I will try and figure out how to do math in flash :) 

parent_mc.width = galleryArr.length * 400 ( i know thats not correct but thats the idea)
Link to post
Share on other sites

Here's a tip. Place all your loaded assets into a blank MovieClip or Sprite. As you add items to the container, the width of the container will change. If you add each new item at an x value that equals the current width of the container, they will all line up nicely.

 

I made a small example to illustrate this concept using a few square movieclips that you can click.

 

import flash.display.MovieClip;
//create empty container clip
var container:MovieClip = new MovieClip();
container.x = 0;
container.y = 100;






addChild(container);


for (var i:int = 0; i < 5; i++) {
this["btn"+i].addEventListener(MouseEvent.CLICK, addToContainer); 
}


function addToContainer(e:MouseEvent):void {
var clickedBtn:MovieClip = e.target as MovieClip;
clickedBtn.x = container.width;
clickedBtn.y = 0;
container.addChild(clickedBtn);
message_txt.y = container.y;
message_txt.x = container.x + container.width;
message_txt.text = String(container.width);
}

dynamicPlacement_CS5.zip

Link to post
Share on other sites

Cool!  what I've been tying to do is modify Easy Infinite Scroll Part 2 and add images using LoaderMax xml loader and the idea is that you can add pics to the folder and reload and bingo, but no matter what I do I get a 0 when trace, parent_mc.length

I made a variable var myWidth:Number = galleryArr.length * 400;  (400 is the with of each mc)

and can trace that but tying to  and set parent_mc to = myWidth i still get a 0

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×