hello,
well i’m trying to get this object to move on the press of a key (keeps moving if you hold it down) and stop when you release it, but all i’m gettin, is when you press it, it moves on forever and never stops…i’ve tried reading this tutorial:
but the code is very confusing, not the actual code itself but the letters and stuff so i dont’ really understand it. Would anyone know another place with a similar tutorial? thx a lot
myMovieClip.onKeyDown = function() {
if (Key.isDown(37)) this._x--; // left
if (Key.isDown(38)) this._y--; // up
if (Key.isDown(39)) this._x++; // right
if (Key.isDown(40)) this._y++; // down
}
Key.addListener(myMovieClip);
or
myMovieClip.onEnterFrame = function() {
if (Key.isDown(37)) this._x--;
if (Key.isDown(38)) this._y--;
if (Key.isDown(39)) this._x++;
if (Key.isDown(40)) this._y++;
}
lairusi - i couldn’t manage to find the example you were talking about? is it in the tutorials section of the flashmx help?
and kax thx for the codes, i dont’ really get hte first one but i think i may get the second. the numbers in brackets are like the numbers for each key right? How did you manage to find them out?
and x-- means to -1 from the previous coordinate right? corect me if i’m wrong…thx for the code again though
ah and i just checked the tutorials in flash about the decrement, and i realized there was a pre and post. I understand that the post decrement returns the original value, but how would you know when to use a pre decrement and a post decrement? Wouldn’t it be better if the code you gave me used a pre decrement so it would -1 from the new number each time?
Heh it’d be great if you could explain that to me, if you understand it, but thx anwyaays
the numbers in brackets are like the numbers for each key right? How did you manage to find them out?
k = new Object();
k.onKeyDown = function() {
trace(Key.getCode());
}
Key.addListener(k);
just kidding
you can find them in the flash help files.
ah and i just checked the tutorials in flash about the decrement, and i realized there was a pre and post. I understand that the post decrement returns the original value, but how would you know when to use a pre decrement and a post decrement? Wouldn’t it be better if the code you gave me used a pre decrement so it would -1 from the new number each time?
honestly… i see no difference in this case. the _x/_y is increased/decreased when you press the key :-\
heh…looks good, but its too advanced for me at the moment it’d take too much explainin for me to get that, just gonna stick with the stuff i understand first