PDA

View Full Version : Trying to call a parent function



richwilliamsuk
February 25th, 2008, 09:49 PM
Hi there,

I'm a bit new with AS3, at the moment i'm struggling to call a parent function. I'm trying to use this.parent.parent.functionhere() and it keeps telling me it's not a function. If i do a trace(parent.parent...etc) it first comes up with the class i'm in, then the container within the parent class, then it misses the parent class and goes straight to the stage.

I'm horribly confused with this display object list malarkey at the moment. Any help is very much appreciated.

Cheers

Rich

restlessdesign
February 25th, 2008, 10:53 PM
Dispatch an event from the child and have the parent object listen for that event. This way, your application will be more loosely-coupled.

richwilliamsuk
February 26th, 2008, 08:52 AM
Dispatch an event from the child and have the parent object listen for that event. This way, your application will be more loosely-coupled.

Thanks very much for the help, I stuck a REMOVE event in and it's working now :)

J_S
March 19th, 2008, 07:27 AM
Can anyone please describe how you can 'Dispatch an event from the child and have the parent object listen for that event.'. I have a movieclip on my stage, and in this movieclip I have this code:


this.addEventListener("mouseOver",DoMouseOver);
function DoMouseOver(evt:MouseEvent){
parent.parent.test();
}

I want to call a function called 'test' which I have made on the stage

ThePuzzleMaster
April 2nd, 2008, 03:00 AM
Is there a way to do this and also send variables, either from parent to child, or child to parent? In a way that would be legal in strict debug mode?

Undernet
April 2nd, 2008, 07:03 AM
Is there a way to do this and also send variables, either from parent to child, or child to parent? In a way that would be legal in strict debug mode?

Yes, Create a custom event class that takes extra parameters and pass the parameters in to the new myEvent object when you dispatch the event.

ThePuzzleMaster
April 2nd, 2008, 08:28 PM
Oh yeah! That should work. Thanks!

libra0
July 17th, 2008, 04:39 PM
i dont understand... :(

can u guys give me a link ou some code to explain.

Regards

libra0
July 17th, 2008, 05:24 PM
got it.. ;)

MovieClip(this.parent.parent).function();