-
onEnterFrame and key.isdown
I'm using the onEnterFrame to capture key presses,
but it is keeping the action too much fast, and I
need to press the keyboard carelly...code: onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
mc.nextFrame;
} else if (Key.isDown(Key.LEFT)) {
mc.prevFrame;
}
};
what can I do to make this whith a interval between the presses automaticaly?
regards
-
Senior Member
here's one suggestion, you may want to create seperate timers for up and down keys. now it's the same time to regulate them both.
Code:
var start_date = new Date();
var start_time = start_date.getTime();
var time_limit = 500;
onEnterFrame = function() {
var now_date = new Date();
var now_time = now_date.getTime();
if(now_time-start_time> time_limit){
if (Key.isDown(Key.RIGHT)) {
mc.nextFrame;
} else if (Key.isDown(Key.LEFT)) {
mc.prevFrame;
}
start_time = now_time;
}
}
use time_limit to controll the intervals
-
great, it works, but when I change time_limit variable,
not happens... why?
-
Senior Member
what do you change it to??
it's defined in milliseconds so you may not notice the changes if they are very small
-
uhh, today I solved the problem:code: time_limit = 200;
start_date = new Date();
start_time = start_date.getTime();
onEnterFrame = function() {
now_date = new Date();
now_time = now_date.getTime();
if (now_time-start_time > time_limit) {
if (Key.isDown(Key.RIGHT)) {
pi.nextFrame();
start_time = now_time;
} else if (Key.isDown(Key.LEFT)) {
pi.prevFrame();
start_time = now_time;
}
}
}
thank you very much.
my movie is working so better
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
|