PDA

View Full Version : on KeyPress question


sebnewyork
02-13-2005, 06:57 PM
I think what I want is very simple, yet I can't figure out how to do it:

When the user presses the SPACE bar, I want an MC to rotate 90 degrees.

But the MC is a variable (mytarget). I have a bunch of MCs, and each of them becomes "mytarget" when selected (pressed on) with the mouse.

I can't figure out how to apply
on (keyPress "<Space>")
to the variable mytarget.
Plus, it seems that
on (keyPress "<Space>")
can only be applied to a button, while it needs to be applied to an MC.

Also, I tried something like

mytarget.onKeyPress(<"Space">) = function() {
etc..

and of course it doesn't work. Well, I tried about a thousand different things.

Please help!

sebnewyork
02-13-2005, 07:10 PM
I also tried creating a button and appying this code toi it:

on (keyPress "<Space>"){
this.mytarget._rotation += 90;
}

not working...
If I replace "mytarget" with one of the MCs instance names, it does work.

How can I make this work with the variable mytarget?

sebnewyork
02-13-2005, 07:25 PM
OK I am realizing that my problem doesn't have anything to do with on Key Press, but just with why the variable "mytarget" is empty.
I don't understand, I use this variable in 5 different functions in my script, all in the first keyframe of the main timeline, and it works just fine.
I set this variable as a global variable, so it should work anywhere anyhow, shouldn't it?

Why isn't this working:

on (keyPress "<Space>"){
this.mytarget._rotation += 90;
}

but this is working:

on (keyPress "<Space>"){
this.actualInstanceName._rotation += 90;
}

PLEASE HELP!!!!!!!!