Reputation: 1269
I have: (1)
this["btn_a"].onRelease = function (){
this._parent[up_mc]._visible = true;
this._parent[add_mc].num = random(10)+190;
trace(this._parent);
}
and I change it to (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();
}
When I click the button in (1), it shows '_level9', but when I click the button in (2), it shows 'undefined'. I know nothing about AS2, so please help me and explain in details. Thanks you very much.
Upvotes: 3
Views: 228
Reputation: 794
scoping....
in the first one, you are calling a function that belongs to the button. in the second, you are declaring a function at a level (your case:level9) and then calling it where it sits.
I think.
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();
}
Upvotes: 3