我在舞台上有一个功能,需要从孩子那里调用它我做的...
// 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...
}
答案 0 :(得分:0)
child_mc.addEventListener(MouseEvent.CLICK, onParentFunction)
onParentFunction(e:MouseEvent)
{
parentFunction();
}
每当您需要在父类上调用函数时,请使用事件。如果您没有点击某个孩子,您可以通过派遣活动来做类似的事情。简单地:
在 child_MC
中dispatchEvent(new Event("SOME_EVENT"));
<强>父强>
child_mc.addEventListener("SOME_EVENT",onSomeEvent);
function onSomeEvent(e:Event):void
{
}
答案 1 :(得分:-1)
此处:
// stage movie
MovieClip(stage.getChildAt(0)).someFunction();