Jump to content
Search Community

Basic understanding, how to set this up

TheToob test
Moderator Tag

Recommended Posts

Hello, first of all I loved greensock before and now I discovered the LoaderMax classes, I continue to do so!

I understand the basic idea of the LoaderMax class. It automatically discovers wether to load a swf, video or image. Brilliant! Then I found out you can manually set up different types of loaders. I can see why that is helpfully if you already know what content type is going to be loaded. Now my 'problem'.

 

I'm creating my portfoliowebsite. There's a bunch of thumbs, and every thumb has a full image, or a swf file, or a video file linked to it. I found out using loaderMax I have little control over the behavior of the loaded content (ie: my swf file plays even when it's not visible). So I imagine I'd use SWF loader when the xml node contains a swf, and the VideoLoader when the xml node contains a videofile. How do I set this up best? My XML looks like this (shortened)










I first load mainThumbs and onComplete i start loading fullContent.

How do I determine the content type of each xml node to alternatively create a VideoLoader or SWFLoader or ImageLoader next? Is that even a good approach to start with!?

Link to comment
Share on other sites

Did you realize that XMLLoader can automatically create all those loaders for you? So if your XML looks like this:

 








 

Then you could do this to load it:

//activate the necessary loader types so that XMLLoader can recognize them
LoaderMax.activate([imageLoader, SWFLoader, VideoLoader]); 

var loader:XMLLoader = new XMLLoader("data.xml", {onComplete:completeHandler});
loader.load();

function completeHandler(event:LoaderEvent):void {
   trace("XML and image1 loaded.");
   var fullContent:LoaderMax = LoaderMax.getLoader("fullContent"); //from the XML
   fullContent.addEventListener(LoaderEvent.COMPLETE, fullComplete);
   fullContent.load();
}

function fullComplete(event:LoaderEvent):void {
   trace("everything loaded!");
}

 

So When XMLLoader loads the XML, it will automatically create the LoaderMax, ImageLoader, SWFLoader, and VideoLoader instances accordingly. You can get them anytime with getLoader() by name or URL.

 

Does that answer your question?

 

PS I didn't quite understand what you meant by "I have little control over the behavior of the loaded content" - LoaderMax gives you a lot of options. It can't, however, prevent a subloaded swf from playing its first frame (that's impossible). Setting autoPlay to false just makes sure that stop() is called on that root when it loads. Were there other reasons you felt like LoaderMax gave you very little control of things?

Link to comment
Share on other sites

Hi Greensock,about the swf autoplay: that indeed clarifies things! Thank you for taking your time to answer this question, really appreciate it!

 

Thanks also for the code sample, I see how I can control the timing when something is loaded. But about the "I have little control over the behavior of the loaded content' -part: I did not put that quite right, I find it hard to do so in English :D , I guess what I meant to say is something more like, when I call getLoader("item1") for instance, and that item is a videofile , I would like to use that source in my videoplayer class, while I have an other class(view) for swf and image files. How do I determine the type of file so I can call the appropriate classes I wrote (about to write) ? (the point is, I don't know when what file will be next, because the XML is going to be dynamic)

Link to comment
Share on other sites

I found out I can get something close to what I think I need, but then again, I can't do anything with it really, so here's what I'm doing:

 

var urls:Array = ["a.jpg", "b.jpg", "c.jpg", "300x250fx_50k.swf"];
		var queue:LoaderMax = LoaderMax.parse(urls, 
			{maxConnections:1,
				onProgress:_progressHandler, 
				onComplete:mainThumbsComplete, 
				onChildComplete:_childCompleteHandler});
		queue.prependURLs("images/portfolio/mainThumb/");
		queue.load();

 

I set up a trace in _childCompleteHandler

trace("child loaded: " + event.target + " inside queue: " + event.currentTarget);

 

Trace:

child loaded: ImageLoader 'loader2' (images/portfolio/mainThumb/a.jpg) inside queue: LoaderMax 'loader1'
child loaded: ImageLoader 'loader3' (images/portfolio/mainThumb/b.jpg) inside queue: LoaderMax 'loader1'
child loaded: ImageLoader 'loader4' (images/portfolio/mainThumb/c.jpg) inside queue: LoaderMax 'loader1'
child loaded: SWFLoader 'loader5' (images/portfolio/mainThumb/300x250fx_50k.swf) inside queue: LoaderMax 'loader1'

 

There you go! It says ImageLoader(3x) and SWFLoader, I needed that, but I can't access it as a value it self... I must be thinking completely wrong here, I'm not the only one using dynamic content via xml, and I see no others struggling with this... :?

Link to comment
Share on other sites

If you want to find out what kind of loader it is, you could do something like this:

 

function childCompleteHandler(event:LoaderEvent):void {
   if (event.target is ImageLoader) {
       trace("this is an image: " + event.target);
   } else if (event.target is VideoLoader) {
       trace("this is a video: " + event.target);
   } else if (event.target is SWFLoader) {
       trace("this is an swf: " + event.target);
   }
}

 

Is that what you're looking for?

Link to comment
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.
×
×
  • Create New...