|
-
Angkor-What?
listerners and functions
I stil;l haven't been able to grasp the whole concept. I have a mc that I want to flip on a keyUp... on a keyDown I want it to flip and move... But with this code it will flip and move no matter what...
Code:
keyListener = new Object();
keyListener.onKeyUp = function() {
Flip();
this.onKeyDown = function() {
Flip();
Move();
};
};
function Flip() {
if (_root.snowman._currentframe == 1) {
if (Key.getCode() == Key.RIGHT) {
_root.snowman._xscale = 100;
}
if (Key.getCode() == Key.LEFT) {
_root.snowman._xscale = -100;
}
}
}
function Move() {
if (_root.snowman._currentframe == 1) {
if (Key.getCode() == Key.RIGHT) {
_root.snowman._xscale = 100;
_root.snowman.play();
_root.snowman.x = x_movement;
}
if (Key.getCode() == Key.LEFT) {
_root.snowman._xscale = -100;
_root.snowman.play();
_root.snowman.x = -1*x_movement;
}
}
}
Key.addListener(keyListener);
Ideas anyone?
Cheers!
MX 2004 Pro - Oops I did it again!!!
SWF, it's a journey... not a destination
-
i dunno if this will apply to you but movieclips dont need to have an added keyListiner
try
onClipEvent(keyDown)
onClipEvent(keyUp)
onClipEvent(keyPress)
or even
onClipEvent(enterFrame)
then to get the keys try
if(Key.isDown(Key.Down))
-
Getting There!
try defining your keyDown outside of your keyUp. Also, do you mean the "down" and "up" keys. Or do you really want one function when any key is actually pressed down and a second when that key is released?
_b
-
Angkor-What?
 Originally Posted by bitsk308
try defining your keyDown outside of your keyUp. Also, do you mean the "down" and "up" keys. Or do you really want one function when any key is actually pressed down and a second when that key is released?
_b
Sorry, wasn't to clear on that but yes! I ment the left and right arrow keys... The keyDown function should only work when the button is being held down for a while...
Cheers
MX 2004 Pro - Oops I did it again!!!
SWF, it's a journey... not a destination
-
Getting There!
in flash, the keyDown event is simple, any time any key is in the down state, the event is triggered and any associated function is executed. If you want this to only work for specific keys, define them. Also, if you only want the function to start after the key's been "down for a while," you'll have to add some kind of counter:
code: keyListener.onKeyDown = function(){
if(Key.isDown(Key.RIGHT) || Key.isDown(Key.LEFT))
counter += 1;
if(counter > 10){
Flip();
Move();
}
}
}
something like that
-
Angkor-What?
Why didn't I think of that 
I changed it a bit
Code:
keyListener.onKeyUp = function() {
start_timer = 0;
};
keyListener.onKeyDown = function() {
if (Key.isDown(Key.RIGHT) || Key.isDown(Key.LEFT)) {
if (start_timer == 0 || start_timer == undefined) {
start_timer = getTimer()/1000;
}
timer = getTimer()/1000;
trace(timer-start_timer);
}
if (timer-start_timer>0.2) {
do etc...
Thanx for that and happy holidays!
Cheers
MX 2004 Pro - Oops I did it again!!!
SWF, it's a journey... not a destination
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|