PDA

View Full Version : "Invisiblity device" on movieclips



fw2803
June 27th, 2007, 01:14 PM
Hello there
I'm trying to make a movieclip invisible when I press "s" (with keycode 83). When I press "s" again, I want it visible again. Alogarithm:

START
IF VISIBLE AND KEYPRESS S
ALPHA = 0
IF INVISIBLE AND KEYPRESS S
ALPHA = 100
END

(I have to use _alpha as I need the intermediate of it later.)

What codes should I use in AS2?

Like this?


onClipEvent (load) {
var invis:Boolean = false
}
onClipEvent (enterFrame) {
if ((invis==false) && (Key.isDown (83))) {
this._alpha = 0
invis = true
}
if ((invis==true) && (Key.isDown (83))) {
this._alpha = 100
invis = false
}
}

But my codes just don't work. Is there something wrong about them?

dthought
June 28th, 2007, 12:04 PM
For some reason I remember reading something like Key.isDown has been disabled as of Flash CS3... not sure if that was for AS3.0 or AS2.0 or both.

Anyway, the best way to deal with key events is to listen for them specifically, rather than having an onEnterFrame constantly poll for whether a key is pressed - that way, you are responding to the appropriate event rather than checking indirectly.

Check out the Key class' listeners in the help file for some examples.