Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Multi-Task

Call Parent Doc Class Public Function from Child

Recommended Posts

Trying to unload a child SWF by calling the parent document class function from the child document class...

 

Loading as such from Main Document class: (SWF loads and plays fine)

if(currAsset is SWFLoader){
	container_mc.addChild(currAsset.rawContent);
	currAsset.rawContent.gotoAndPlay(1);
	
}

Also, within Main Document Class:

public function swfFinished():void {
	var currAsset = media.getChildAt(mediaTracker-1);
	currAsset.content.visible = false;
	currAsset.rawContent.gotoAndStop(1);
	container_mc.removeChildAt(0);
	currAsset=null;
	//set up and play the next swf
	managePlayBack();
}

Then -

From the Child SWFs Main Document Class:

This function is fired once the SWF is done (last frame of SWF calls this), this fires but doesnt trigger parent function of swfFinished().  

private function done():void {
	var curParent:MovieClip = this.parent.parent.root as MovieClip;
   	curParent.swfFinished();
}

Any ideas?

 

Link to comment
Share on other sites

From the child swf, this.parent says its referencing the stage.  

 

so this.parent.parent should be the container_mc?  

 

adding another parent (this.parent.parent.parent) should be the stage of the parent application?

 

but what about the document class of that parent?  :/

 

I should add that these sub SWFs are being loaded into an AIR app.  SWFs are pulled from Server...  Am I even able to access the public functions within the AIR app from the loaded SWFs?

Link to comment
Share on other sites

Thanks Carl for helping out...

 

So I added a simple text field on stage to try to determine what is being referenced and for displaying errors.

 

Environment:

AIR app runs on desktop and loads in externally hosted SWF files.  This all works great since I have a crossdomain policy in place.

 

However; after your suggestions.  I am getting a #2047 error.  Any ideas?  Is it not possible to call public functions of an AIR app from externally hosted SWFS?

private function showSomething():void {
	try {
		this.dText.text = "parent  " + MovieClip(this.parent.parent.parent.parent);
	} catch(e:Error) {
		this.dText.text = e.errorID+"\nError Message : "+e.message;
	}
			
}
		
private function done():void {
	this.dText.text = "done";
	var curParent:MovieClip = this.parent.parent.parent.parent as MovieClip;
   	curParent.swfFinished();
}
Link to comment
Share on other sites

If this is not possible given my scenario, do you know of any work arounds?  I was thinking about adding some custom listeners and events but not sure if that would even help in this scenario.

Link to comment
Share on other sites

Side note...

 

To set back the SWF timeline of the child swf, is it

someAsset.rawContent.gotoAndStop(1);

or 

someAsset.content.gotoAndStop(1);

 

These would all be loaded into the container_mc

Link to comment
Share on other sites

Yeah those 2047 errors have to do with security violations. Not really sure what in your environment is causing that.

 

To communicate with a loaded swf via its SWFLoader use

 

someSWFLoader.rawContent.gotoAndPlay(1)

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