hi,
i have a button inside an MC,
when i try to do :
code:
on(release)
{
trace(_parent.myMC._name);
}
i got "undefined".. why my button dont recognize his _parent as the MC?
(i attached sample file)
Printable View
hi,
i have a button inside an MC,
when i try to do :
code:
on(release)
{
trace(_parent.myMC._name);
}
i got "undefined".. why my button dont recognize his _parent as the MC?
(i attached sample file)
code:
on(release){
trace(this._name);
}
really? wheeew...
and what if i need to get the pointer of the button itself?
any other cases i would use "this"... what about this case?
You can get a reference to the button inside a button event handler by using this.buttonname (assuming the button is named).
Also, in event handlers that are setup from frame scripts (as opposed to scripts attached to movieclips or buttons), this does still refer to the button - these scripts are handled more uniformly.
The numerous little differences in syntax between frame scripts and movie-clip/button scripts are an endless source of confusion for folks here.
Now some opinion:
The main reason for using buttons (as opposed to movieclips) is when the button GUI (how the button graphically responds to rollover and clicking) is really simple and you don't need to refer to the button from a script.
If you're doing anything remotely complicated, use a movieclip instead of a button - then this will refer to the thing you are pressing (the 'button') and this._parent will refer to the thing it is attached to.
In my own code, I've pretty much abandonded the use of buttons entirely.