Jump to content
Search Community

LoadeMax question

acto test
Moderator Tag

Recommended Posts

Hi,

 

I'm building a presentation with loaderMax and I would like to know if I can load multiple swfs using the same function, here is the code I have but it doesn't work, it only loads the first swf but not the rest:

 

function loadSubSections(): void {
var loader:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

if (s01Instance == s01S01 && s01S01Loaded != 1) {
	loader.append( new SWFLoader("s01_01.swf", {name:"s01", estimatedBytes:3000, container:Object(root).s01s01_container, autoPlay:true}) );

} else if(tableOn == 1 && tableLoaded != 1) {
	loader.append( new SWFLoader("s01_02.swf", {name:"s02", estimatedBytes:3000, container:Object(root).menu_slide.kwestia_container, autoPlay:true}) );
}

loader.load();

function progressHandler(event:LoaderEvent):void {
 trace("progress: " + event.target.progress);

}
 
function completeHandler(event:LoaderEvent):void {
 trace(event.target + " is complete!");

}
function errorHandler(event:LoaderEvent):void {
    trace("error occured with " + event.target + ": " + event.text);
}
} 

 

I would like to have one function loadSubSections(); and use it with if and else if arguments to load different swfs, in different containers is this possible?

 

Thank you,

 

acto

Link to comment
Share on other sites

The main benefit of LoaderMax is that you can store multiple loaders in one queue / list and then

-load all subloaders in sequence

-prioritize certain loaders

-pause the load sequence

-resume the load sequence

-easily communicating with each loader after its loaded via LoaderMax.getLoader() or LoaderMax.getContent()

etc.

 

Every time your loadSubSection function is called you are creating a new loader:LoaderMax and appending 1 SWFLoader to it... so you really don't have a queue just a single SWFLoader in a LoaderMax.

You could probably get away with just creating a new SWFLoader each time on its own and have the same functionality.

 

Also, by declaring var loader:LoaderMax = new LoaderMax(...) inside the function you don't have access to that LoaderMax anywhere else in your code.

 

The following code sets up a LoaderMax instance that has 3 ImageLoaders (will be the same for swf).

To simulate a single function that loads a different asset into a different container I just am making a new asset load each time the user clicks on the stage. your if else statements do virtually the same thing. also each loader uses the same onComplete and onProgress handlers.


import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;


var queue:LoaderMax = new LoaderMax({name:"mainQueue"});


queue.append( new ImageLoader("images/photo1.jpg", {name:"photo1", container:container1, alpha:0,  onProgress:progressHandler, onComplete:completeHandler}) );
queue.append( new ImageLoader("images/photo2.jpg", {name:"photo2", container:container2, alpha:0,  onProgress:progressHandler, onComplete:completeHandler}) );
queue.append( new ImageLoader("images/photo3.jpg", {name:"photo3", container:container3, alpha:0,  onProgress:progressHandler, onComplete:completeHandler}) );


var loadIndex:int = 0;
stage.addEventListener(MouseEvent.CLICK, loadNext);

function loadNext(e:Event){
loadIndex++;
switch(loadIndex){
	case 1:
//load the first asset
	LoaderMax.getLoader("photo1").load();
	break;

	case 2:
//load the second asset
	LoaderMax.getLoader("photo2").load();
	break;

	case 3:
//load the third asset
	LoaderMax.getLoader("photo3").load();
	break;

	default:
	trace("stop clicking, i'm done!");
	break;
	}



}

function progressHandler(event:LoaderEvent):void {
   trace("progress: " + event.target.progress);
}

function completeHandler(event:LoaderEvent):void {
   var image:ContentDisplay = event.target.content;
   TweenLite.to(image, 1, {alpha:1});
   trace(event.target + " is complete!");

}

 

hopefully that code will give you some ideas on how to progress.

Also, although I pointed out a few ways to make your code a little more flexible, I'm not seeing anything exactly wrong or that would prevent an asset from loading.

I would put some trace() statements in each condition to make sure the logic is sound BEFORE moving forward.

 

-Carl

Link to comment
Share on other sites

Hi Carl,

 

Thank you for your help, I really appreciate it, I rewrote my code and it looks like this:

 

var queue:LoaderMax = new LoaderMax({name:"mainQueue"});


queue.append( new SWFLoader("s01_01.swf", {name:"salon", container:Object(root).s01s01_container,  onProgress:progressHandler, onComplete:completeHandler}) );
queue.append( new SWFLoader("kwestia.swf", {name:"kwestia", container:Object(root).menu_slide.kwestia_holder,  onProgress:progressHandler, onComplete:completeHandler}) );


function loadSubSections(): void {
if (s01Instance == s01S01 && s01S01Loaded != 1) {
	LoaderMax.getLoader("salon").load();

} else if(tableOn == 1 && tableLoaded != 1) {
	LoaderMax.getLoader("kwestia").load();
}
}

function progressHandler(event:LoaderEvent):void {
   trace("progress: " + event.target.progress);
}

function completeHandler(event:LoaderEvent):void {
   var image:ContentDisplay = event.target.content;
   trace(event.target + " is complete!");

}

 

The only problem is that my second swf still doesn't load... do you see anything wrong with my code? Am I missing something.

 

All the best,

 

acto

Link to comment
Share on other sites

Also, if I switch the loaders like so:

 

function loadSubSections(): void {
  if (s01Instance == s01S01 && s01S01Loaded != 1) {
     LoaderMax.getLoader("kwestia").load();

} else if(tableOn == 1 && tableLoaded != 1) {
     LoaderMax.getLoader("salon").load();
}

 

The kwestia.swf loads fine but the second swf doesn't, so there is no problem with my swf, or container, it must be something in the code...

 

Please help,

 

acto

Link to comment
Share on other sites

Strange thing, when I use if instead of else if it works...

 

function loadSubSections(): void {
if (s01Instance == s01S01 && s01S01Loaded != 1) {
	LoaderMax.getLoader("salon").load();

} if (tableOn == 1 && tableLoaded != 1) {
	LoaderMax.getLoader("kwestia").load();
}
}

 

But I don't understand why else if doesn't work....

 

:/

 

acto

Link to comment
Share on other sites

when the first if is true, the else will not run.

 

chances are when the first if runs, the condition is true and then remains true.

 

in your first if you should trace out the values of s01Instance and s01s01Loaded. i have a hunch s010s01Loaded is not what you think it is. give it a try.

Link to comment
Share on other sites

Yes, s010s01Loaded is my var that is set after the loading is complete and it doesn't change, s01Instance is the var tracking which instance is being clicked and this doesn't change until the user finishes exploring the whole section or gets back to root. This works fine the way it is with the if statements instead of else if, is it wrong to use the if statements like this? If it is, I will try to fix this, but I hope that it's OK :)

 

Thank you for your help!

 

acto

Link to comment
Share on other sites

the only concern i have is that the first condition may still be firing and you may be loading 2 things at once.

 

if(condition1 == true){
//do result1

}else if(condition2 == true){
//do result2
}

 

in the above scenario using else if, if condition1 is true, then condition2 never gets tested.

 

when you stack the same if statements like:

 

if(condition1 == true){
//do result1

}if (condition1 == true){
//do result2
}

 

 

and you are seeing result2 work: LoaderMax.getLoader("kwestia").load();

 

I would think that conditon1 is still true and you are also loading LoaderMax.getLoader("salon").load();

 

I think nothing is changing in your app to ever make condition1 false that's why the else if statement never ran. put a trace in each if block and see what happens.

 

function loadSubSections(): void {
  if (s01Instance == s01S01 && s01S01Loaded != 1) {
trace("condition1");
     LoaderMax.getLoader("salon").load();

} if (tableOn == 1 && tableLoaded != 1) {
trace("condition2");
     LoaderMax.getLoader("kwestia").load();
}
}

Link to comment
Share on other sites

Thank you,

 

What you wrote is true, but this is why I have the xxxLoaded vars, the loadings occur only if they are != 1 and I set them to ==1 with the completeHandler, when I test the movie, everything works, I am just concerned with the use of if instead of else if, is this an acceptable method or do I risk getting errors?

 

All the best,

 

acto

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...