Jump to content
Search Community

some method to unload the subSWF itself?

biyibird test
Moderator Tag

Recommended Posts

Hi,greensock:

 

I have a question about "SWFLoader.unload()".

The "main.swf" have loaded "rect.swf",and I want to click the stage, to unload rect.swf (after play a tweemMax).

The code works well now.

 

///////////////main.as
var _current;
public function testUnload(){
var loader:SWFLoader = new SWFLoader("rect.swf", {name: "mainSWF", container: this,  onComplete: completeH});
loader.load();
stage.addEventListener(MouseEvent.CLICK, click);
}

private function completeH(e:LoaderEvent):void {
_current = e.target.rawContent;
_current.addEventListener("unload", function() { e.target.unload(); } );
}

private function click(e:Event):void {
_current.tweenAndDispatch();
}

 

/////////////rect.as
public function rect() {}
public function tweenAndDispatch() {
TweenMax.to(this, 1.5, { height: 10, onComplete:function() {
	dispatchEvent(new Event("unload"));
}});
}

 

 

but if there's some method ,to write the code of “......unload()....”into the class of "rect.as",to let the class of rect.as to unload ITSELF?

Link to comment
Share on other sites

Assuming you didn't remove the rawContent from the ContentDisplay, you should be able to go up the parent chain and look for the ContentDisplay, like:

 

var curParent:DisplayObjectContainer = this.parent;
while (curParent) { 
   if (curParent.hasOwnProperty("loader") && curParent.hasOwnProperty("rawContent")) {
       Object(curParent).loader.unload(); 
       break;
   }
   curParent = curParent.parent;
}

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