Here is an interesting thing. I had this code working, then made some changes to fla and now it does not work at all! I have not altered this code a bit but now it does not work. Have you ever experienced this? I even tried recoding it in 'save as' version and it did not work there either!
this.onEnterFrame = function () { moveMe.apply (this); };
moveMe = function () {
if (Key.isDown(Key.LEFT)) {
if (this._x < left) {
this._x -= 5;
} else {
this._x = left;
}
}
if (Key.isDown(Key.RIGHT)) {
if (this._x < right) {
this._x += 5;
} else {
this._x = right;
}
}
};
Any thoughts on why this does not work and what ought to fix it?
where are the vars left and right coming from?
The function is tracing okay, it's just not passing those if statements because I haven't set them.
What do you get for traces when you run:
this.onEnterFrame = function () { moveMe.apply (this); };
moveMe = function () { if (Key.isDown(Key.LEFT)) { trace("left!"); if (this._x < left) { this._x -= 5; trace("left fired!"); } else { this._x = left; } } if (Key.isDown(Key.RIGHT)) { trace("right!"); if (this._x < right) { this._x += 5; trace("right fired!"); } else { this._x = right; } } };
?
The 'left' and 'right' are _global. I am using them to define a box on my main stage. As far as the trace goes, I had tried that and nothing was traced. Now that is really weird to me. If I put other code on the same frame, it works. I just cannot get this section to work like it did initially.
F r u s t r a t i o n.
Any other ideas? Oh, this seems to work fine on a brand new movie, just not the one I need it to work with.
wird. I can see why your getting frustrated.
try this on it and see if the function is even firing:
this.onEnterFrame = function () { moveMe.apply (this); };
moveMe = function () { trace("yes I am actually firing here."); };
so i know it is reading my function. It just seems to be an issue with the Key.isDown(). More interesting twists, this works:
on (keyPress "f")
but I do not want to have everything set up on buttons.
warrg:mad:
did you lock the left and right keys? are you using them for something else as well?
this is so weird!
Yeah, I did check that. I had the same thought, but there are only three keys that are 'active' in this movie, the LEFT, RIGHT and 'f' (which is the button command). So I switched them to keys that I knew were not in use, SHIFT and DELETE. Still nothing!
Man, what a pain in the brain this is becoming. I have, in the past, experienced times where my AS, for whatever reason, breaks after modifying it. I have never seen Flash just totally disregard an entire object class though. No matter where I put it in my movie it still refuses to recognize that I am pressing keys using the Key.isDown() method.
I am currently devising a workaround using buttons, but that is not what I wanted it to do. I suppose in the end it will function the same, but now it is a matter of conquering the .fla and getting this to work.
Any further thoughts would be appreciated 
tp={}; tp.onKeyDown=function(){ trace(Key.getCode()); } Key.addListener(tp);
this script might help you in some way? masa.
Thank you for the idea!
It works just as well as the button method. For whatever reason, if I check against the getCode() it works out, but if I am just looking for isDown() Flash acts as though it has no idea what key is being pressed.
Freaky glitch.
Still wish I could get isDown to work, just so it works. Ah well, I can save that for another day.
Thanks to you both for your help.
- Craig