[FMX] Help on Key. command

I am trying to make a couple of Movieclips hide on the holding down of a key such as Page down ive used this:

onClipEvent (keyDown) {
if (Key.isDown(Key.PGDN)) {
_root.cupa._visible = false;
_root.cupb._visible = false;
_root.cupc._visible = false;
}

it hides the MC but doesnt return visible on release of PGDN. Ive had a go at trying to fix this but i cant find the right command in the actionscript dictionary. I know theres an easier way i just need help. Also is it possible for the MC to hide only on the holding down of multiple keys.

thats because you didnt include any code to do so. Things dont happen unless you tell them to. Right now you have an action that says something to the effect of

At the moment in time when a key is pressed, if that key is page-down, then make the following clips invisible

nothing there about changing them back.

one thing you can do is instead put the action in an enterframe (so it continuously checks the state of page down) and EVEN, and I hope you learn from this trick ;), set the visibility of those clips TO the value of page down - or actually the opposite. Since what Key.isDown gives you is a true or false value and what you are assigning thsoe clips visibility to be is true or false, you can skip the if statement all together and just have _visible = Key.isDown, but really, in your case, the opposite (since you want the visible to be false when pagedown is down is true) - at which case you use the exlamation point “!” which represents “not”. ! reverses things and youve probably (maybe) used it in checking for inequality like if(x != 4) <– which is if x is not equal to 4. So what you can do is…


onClipEvent (enterFrame) {
_root.cupa._visible = _root.cupb._visible = _root.cupc._visible = !Key.isDown(Key.PGDN);
}

^btw, if you have a lot of variables or properties equalling the same thing, you can string them together like that and shrink three lines of code into 1.

So what thats doing is checking everyframe and setting the visible properties of those clips to NOT the key pagedown is down. So if pagedown is not down, that returns a false meaning the !false is true making all the visible properties true. If it is down, key.isdown is true, !true is false and all the visible properties are false

wow thanks a lot, exactly what i was looking for.:beam:

I knew i didnt have any code in there to tell it to change back but it was because i wasnt sure how to do it.