2011-12-24 51 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