Jump to content
Search Community

preload all the videos before start to play

andresapitt test
Moderator Tag

Recommended Posts

Hi, i am building a game that consist in a series of videos. I was following Michael B Tutorial on how to build a Smart AS3 Video Loading and Playback with GreenSock LoaderMax. And it works fine is just that i want to be sure to start the game once all the videos have been preloaded so there is no delay switching between video. is this posible?

SO I´ll have an xml with all the video that need to be played in that scene, preload them and then depending on user interaction I´ll play all of them, the thing is that the order will not allway be the same as could change depending on user input, that´s why they need to be preloaded to start as soon as posible when i have the user´s custimized play order.

Regards,

Andres

Link to comment
Share on other sites

Absolutely. That's one of the core competencies of LoaderMax. Just create a LoaderMax queue, append() your VideoLoaders, and add a COMPLETE event listener - that will tell you when they're all done.

var queue:LoaderMax = new LoaderMax({onComplete:completeHandler});
queue.append( new VideoLoader(...) );
queue.append( new VideoLoader(...) );
...
queue.load();

function completeHandler(event:LoaderEvent):void {
   trace("done!");
}

Link to comment
Share on other sites

It depends on your XML. Are you using nodes in your XML to take advantage of the automatic parsing the XMLLoader does? If so, all you need to do is make sure you set autoPlay="false" on your nodes and then grab them with LoaderMax.getLoader() or LoaderMax.getContent() when the XMLLoader finishes.

Link to comment
Share on other sites

It depends on your XML. Are you using nodes in your XML to take advantage of the automatic parsing the XMLLoader does? If so, all you need to do is make sure you set autoPlay="false" on your nodes and then grab them with LoaderMax.getLoader() or LoaderMax.getContent() when the XMLLoader finishes.

 

Yes i do use:

<?xml version="1.0" encoding="iso-8859-1"?> 






 

And then in flash i do:

private function xmlHandler(event:LoaderEvent):void {			
		var queue:LoaderMax = LoaderMax.getLoader("videoListLoader");					
		//store the nested VideoLoaders in an array
		_videos = queue.getChildren();		
		queue.load(); 
		}

Regards,

ANdres.

Link to comment
Share on other sites

Great - did you still have a question?

 

Just so you know, you could set load="true" in the node to make it automatically load all of the child loaders in the XML. Not necessary - just wanted to make sure you knew that.

 

Yes i still struggling to fire the complete event when all the video form the XML are loaded

how do you add a onComplete event to var queue:LoaderMax = LoaderMax.getLoader("videoListLoader");

I tried an addEventListener and it didn´t work.

Regards,

Andres.

Link to comment
Share on other sites

Great - did you still have a question?

 

Just so you know, you could set load="true" in the node to make it automatically load all of the child loaders in the XML. Not necessary - just wanted to make sure you knew that.

IT´s ood but if i try to include load="true" in the the applicacion doesn´t work, it doesn´t load the xml at all.

 

So am still stuck trying to load all the video before starting to play: i have:

 

private function XMLCompleted(event:LoaderEvent):void {

 

var queue:LoaderMax = LoaderMax.getLoader("videoListLoader");

 

//store the nested VideoLoaders in an array

_videos = queue.getChildren();

//start loading the queue of VideoLoaders (they will load in sequence)

queue.load();

// now i want to wait until all the videos are downloaded before strint to play the first one.

 

}

 

private function completeHandler(event:LoaderEvent):void {

trace("done!");

//once they are all dowloaded start playing the first one

showVideo(_videos[0]);

 

}

Link to comment
Share on other sites

How do you add a onComplete event to var queue:LoaderMax = LoaderMax.getLoader("videoListLoader");

I tried an addEventListener and it didn't work.

Sure, you can addEventListener() like this:

 

var queue:LoaderMax = LoaderMax.getLoader("videoListLoader");
queue.addEventListener(LoaderEvent.COMPLETE, completeHandler);

 

However, please make sure you're using the latest version of LoaderMax (updated last night) because if you're publishing to Flash Player 9 and you're using the version of LoaderMax that was on the site within the last 2 days, there was a bug that could cause VideoLoaders not to dispatch their COMPLETE events properly. Of course that has been resolved in the latest version.

 

IT's ood but if i try to include load="true" in the the applicacion doesn´t work, it doesn't load the xml at all.

I'm very confused - putting load="true" in the node makes the XML not load at all? I'd be shocked if that's the case - please post an example FLA that demonstrates the problem so that I can compile it here and see what's going on. Include your XML too please and any other support files. It doesn't need to be all your production files - I'd much prefer to get a separate, very simple FLA with only the code necessary to reproduce the issue.

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