2009-06-15 13 views
3

:(1)シンプルAS2問題

this["btn_a"].onRelease = function(){ 
    this._parent[up_mc]._visible = true; 
    this._parent[add_mc].num = random(10)+190; 
    trace(this._parent); 
} 

と私は(1)のボタンをクリックすると、それは_level9 'を示し、(2)

function click1(){ 
    this._parent[up_mc]._visible = true; 
    this._parent[add_mc].num = random(10)+190; 
    trace(this._parent); 
} 
this["btn_a"].onRelease = function(){ 
    click1(); 
} 

に変更します(2)のボタンをクリックすると、「未定義」と表示されます。私はAS2について何も知らないので、私を助けて詳細に説明してください。どうもありがとうございます。最初の1で

答えて

3

スコープ....

、あなたはボタンに属する関数を呼び出しています。 2番目のレベルでは、レベル(あなたのケース:レベル9)で関数を宣言し、その関数が座っている場所で関数を呼び出しています。

だと思います。

this["btn_a"].onRelease = function(){ 
    trace(this._parent+" "+this); // traces: _level0 _level0.btn_a 
} 

function click1(){ 
    trace(this._parent+" "+this); // traces: undefined _level0 
} 
this["btn_b"].onRelease = function(){ 
    click1(); 
}