2011-12-24 37 views
1

我想从动画片段“B”控制动画片段“A”组件。可能从另一个影片剪辑控制movieclip组件?

影片剪辑答:

function click1(event:MouseEvent):void 
{ 
    // I want to change text of button which is inside movieclip "B" in here. 
} 

btn1.addEventListener(MouseEvent.CLICK , click1); 

影片剪辑B:

function click2(event:MouseEvent):void 
{ 
    //and here I want to change text of button which is inside movieclip "A". 
} 

btn2.addEventListener(MouseEvent.CLICK , click2); 

我该怎么办呢?

对不起,我的英语。

回答

3

使这两个影片剪辑(mcamcb)已经被添加到stage假设 - stage既是母公司 - 这是非常简单:

function click1(event:MouseEvent):void 
{ 
    // I want to change text of button which is inside movieclip "B" in here. 
    stage.mca.someButtonObject.label = "some new button text"; 
} 

function click2(event:MouseEvent):void 
{ 
    //and here I want to change text of button which is inside movieclip "A". 
    stage.mcb.someTextboxObject.text = "some new text"; 
} 

测试此代码了一下,并让我知道如果这不起作用(如果失败,请发布您的代码)。

+0

如果您在2个影片剪辑的父级中声明您的代码,您可以将范围只声明为'mca.someButtonObject.label = ...'而不包括'stage' – ToddBFisher 2011-12-26 16:17:07

+0

@TdBdBFisher感谢您指出出更一般的情况。理论上讲,使用一个共同的祖先(父母等通常最接近的)。 – iND 2011-12-26 16:42:48

相关问题