PDA

View Full Version : using 'this'


glospinner
04-09-2002, 02:48 PM
Alright, i'm a little embarrassed to be asking this one, since I'm pretty familiar with Flash, but i've never fully understood the usage of the 'this' statement. (I'm gonna have to keep using quotes around 'this' so that you know when I'm talking about the code, and not some scenario or something) =)

I realize that 'this' is a reference to the current timeline, for instance, to hide a movieClip from within the movie clip, you could just do this._visibility = false; or whatever. The part that I'm unsure about is if, say, you want to hide that movie clip when you click on a button in the movie clip. Would this._visibility = false in an on(press) event hide the movie clip or the button? Cuz it seems to me that the current timeline is the buttons timeline. But on the otherhand, the actionscript resides actually on the object and not in it's timeline.... sooo you can understand my confusion. Which timeline would 'this' refer to?

Thanks

pinkaboo
04-09-2002, 03:35 PM
btw it's not
on (release) {
this._visibility = false;
}


it's:

on (release) {
this._visible = false;
}



this would refer to the movieclip directly containing the button

I think there a relevant tute in the tutorials section

farafiro
04-09-2002, 03:44 PM
Also u can check the Macromedia site or see the help in Flash 5 in the "what's new" section

red penguin
04-11-2002, 02:07 AM
Another good example is to make a function. Something like...

// on the root...
function move(clip, x, y){
clip._x = random(x);
clip._y = random(y);
}

And then use it using this ...

// on a clip...
onClipEvent(load){
_root.move(this, 400, 400);
}