Jump to content
Search Community

unloading loadermax and removing children

rikbogusz test
Moderator Tag

Recommended Posts

i'm getting my head around this, but a few things i still just don't know how to do properly. i've created a loadermax which loads a number of videoloaders, some with audio, some not. in the movieclip, i have buttons to play each clip. i load them and play them ok, but my unloading and removing children skills are pretty weak. it's not really noticeable until a clip with audio is played, then a clip with no audio is chosen, the newly selected clip plays, but the audio from the previously loaded clip plays with it. here's my code

var loader:VideoLoader = new VideoLoader("flv/1_form.flv",{name:"videoone",width:870,height:480,scaleMode:"proportionalInside",bgColor:0x000000,bgAlpha:0,autoPlay:false,volume:0,repeat:-1,requireWithRoot:this.root,estimatedBytes:75000});
var loader2:VideoLoader = new VideoLoader("flv/2_drapelift.flv",{name:"videotwo",width:870,height:480,scaleMode:"proportionalInside",bgColor:0x000000,bgAlpha:0,autoPlay:false,volume:0,repeat:-1,requireWithRoot:this.root,estimatedBytes:75000});
var loader3:VideoLoader = new VideoLoader("flv/3_washoff.flv",{name:"videothr",width:870,height:480,scaleMode:"proportionalInside",bgColor:0x000000,bgAlpha:0,autoPlay:false,volume:0,repeat:-1,requireWithRoot:this.root,estimatedBytes:75000});
var loader4:VideoLoader = new VideoLoader("flv/4_coverage.flv",{name:"videofor",width:870,height:480,scaleMode:"proportionalInside",bgColor:0x000000,bgAlpha:0,autoPlay:false,volume:1,repeat:0,requireWithRoot:this.root,estimatedBytes:75000});

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

queue.append( loader );
queue.append( loader2 );
queue.append( loader3 );
queue.append( loader4 );

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

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

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

ch6_btn1.buttonMode = true;
ch6_btn1.mouseChildren = false;
ch6_btn1.addEventListener(MouseEvent.CLICK, btnDown_ch6_1);

function btnDown_ch6_1(e:MouseEvent):void
{
queue.unload();
queue.load( loader );
var content:ContentDisplay = LoaderMax.getContent("loader");
addChild(loader.content);
loader.gotoVideoTime(0, true);
}

ch6_btn2.buttonMode = true;
ch6_btn2.mouseChildren = false;
ch6_btn2.addEventListener(MouseEvent.CLICK, btnDown_ch6_2);

function btnDown_ch6_2(e:MouseEvent):void
{
queue.unload();
queue.load( loader2 );
var content:ContentDisplay = LoaderMax.getContent("loader2");
addChild(loader2.content);
loader2.gotoVideoTime(0,true);
}

ch6_btn3.buttonMode = true;
ch6_btn3.mouseChildren = false;
ch6_btn3.addEventListener(MouseEvent.CLICK, btnDown_ch6_3);

function btnDown_ch6_3(e:MouseEvent):void
{
queue.unload();
queue.load( loader3 );
var content:ContentDisplay = LoaderMax.getContent("loader3");
addChild(loader3.content);
loader3.gotoVideoTime(0,true);
}

ch6_btn4.buttonMode = true;
ch6_btn4.mouseChildren = false;
ch6_btn4.addEventListener(MouseEvent.CLICK, btnDown_ch6_4);

function btnDown_ch6_4(e:MouseEvent):void
{
queue.unload();
queue.load( loader4 );
var content:ContentDisplay = LoaderMax.getContent("loader4");
addChild(loader4.content);
loader4.gotoVideoTime(0,true);
}

 

i think what i need to do is load and unload into the same child, but i really haven't grasped how to do that yet. if anyone can help today i'd greatly appreciate it, this is for an application to be used at a tradeshow that starts tomorrow! (and i can't wait til i get paid for this project, it's time to join club greensock!)

Link to comment
Share on other sites

You unload() the entire queue each time someone clicks a button. When you unload(), that dumps all the content that was loaded (I don't think you want that). And then you queue.load( loader ) but that doesn't make sense - the load() method only has one parameter and it's a Boolean (true/false) that indicates whether or not you want to flush (unload) existing content. To load a particular loaded, simply call load() on that loader like loader.load().

 

As far as adding/removing children, you should probably create a variable that tracks the currently playing/showing video and then make sure you pauseVideo() and removeChild() that before you addChild() the new one and play it. Kinda like:

 

var curVideo:VideoLoader;

function btnDown_ch6_1(e:MouseEvent):void {
  if (curVideo != null) {
      curVideo.pauseVideo();
      removeChild(curVideo.content);
  }
  curVideo = LoaderMax.getLoader("loader2");
  addChild(curVideo.content);
  curVideo.gotoVideoTime(0, true);
}

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