Jump to content
Search Community

Contentdisplay and dispose() error

ilanb test
Moderator Tag

Recommended Posts

Hi,

 

When the first two video are completed I try to delete before playing 2 other videos but if I use dipose, unload... (VIDEO_COMPLETE) I have an 1009 error

 

If I try to use removeChild methode it's same.

 

public function loadContentCritical():void
	{

		//activate the loaders
		LoaderMax.activate([VideoLoader]); 

		var urls:Array = ["3_DialS1_P1.flv", "3_DialS1_V1.flv", "3_DialS1_P2.flv", "3_DialS1_V2.flv", "3_DialS1_P3.flv", "3_DialS1_V3.flv", "3_DialS1_P4.flv", "3_DialS1_V4.flv", "3_DialS1_P5.flv", "3_DialS1_V5.flv", "3_DialS1_P6.flv", "3_DialS1_V6.flv", "3_DialS1_P7.flv", "3_DialS1_V7.flv", "Left.flv", "Right.flv", "Sad.flv", "Wait1.flv", "Wait2.flv", "Wait3.flv", "Wait4.flv", "WaitV1.flv"];
		queue = LoaderMax.parse(urls, 
			{maxConnections:3,
				onProgress:_progressHandler, 
				onComplete:_queueCompleteHandler, 
				onChildComplete:_childCompleteHandler}, {autoPlay:false});
		queue.prependURLs("files/assets/flv/critical/");
		queue.load();

	}

	private function _queueCompleteHandler(event:LoaderEvent):void {

		var loaders:Array = queue.getChildren();
		var videos:VideoLoader = loaders[1];
		addChild(videos.content);
		videos.playVideo();

		videos = loaders[17]; //reuse the videoP variable
		addChild(videos.content);
		videos.playVideo();


		videos.addEventListener(VideoLoader.VIDEO_COMPLETE, onVideoComplete, false, 0, true);

	}


	private function onVideoComplete(_event:Event):void {

		//videos.unload();
		videos.dispose(true);

		var loaders:Array = queue.getChildren();
		var videos:VideoLoader = loaders[0];
		addChild(videos.content);
		videos.playVideo();

		videos = loaders[21];
		addChild(videos.content);
		videos.playVideo();


	}

 

How I can remove videos and play next ?

 

Thanks

Link to comment
Share on other sites

There are several problems with your code:

 

1) You create a local "videos" variable inside your _queueCompleteHandler() method and then you try to reference it inside another function, onVideoComplete(). You can't do that. Local variables only exist within the function where they are defined. You could, of course, define that variable as a class-level variable instead if you need to access it other places.

 

2) If you dispose() one of the VideoLoaders in your LoaderMax, keep in mind that it will be...disposed...gone...vamoose...removed. Your code looks like it relies on loaders being at specific index values of the LoaderMax but that's a dangerous way to engineer things. Imagine you've got 20 loaders and you load the first and second ones (index 0 and 1). Then you dispose - since those get deleted from the LoaderMax queue, the index values shift, so what USED to be index 2 and 3 now become index 0 and 1. See the problem? It isn't a "wrong" way to code your stuff, but you just need to be careful about the whole index thing. It might be better to reference your loaders based on their name or url using LoaderMax.getLoader("myLoaderNameOrURL");

Link to comment
Share on other sites

Thanks Jack,

 

It's much clearer now !!

 

I have created a generic videoloader class and use

_genericVideosLoader.playVideoByIndex(cpt);

to play video and

public function videoEnd():void 
	{

		return _currentVideo.unload();

	}

 

to unload

 

Work like a charm :-)

 

I have found good tuts to help me a lot : http://active.tutsplus.com/tutorials/actionscript/smart-as3-video-loading-with-greensock-loadermax-free-active-premium/ :mrgreen:

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