I have a function in stage and need to call it from a child I do I do it…
// In main stage
var child_mc:mcChild = new mcChild();
addChild(child_mc);
function parentFunction():void
{
trace("Do something here");
}
// inside mcChild
button_mc.addEventListener(MouseEvent.CLICK, callParentFunction);
function callParentFunction(e:MouseEvent):void
{
// here I need to call the function that is in the main stage.
// I tried
// parent.parentFunction();
// and
// root.parentFunction(); but nothing works...
}
Whenever you need to call a function on a parent class then use events. If you were not clicking on a child you can do something similar by dispatching an event. Simply:
In child_MC
Parent