dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: onEnterFrame and key.isdown

  1. #1
    graphic designer
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    112

    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
    |calve|brazil|

  2. #2
    Senior Member k/smaert's Avatar
    Join Date
    Dec 2003
    Posts
    210
    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

  3. #3
    graphic designer
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    112
    great, it works, but when I change time_limit variable,
    not happens... why?
    |calve|brazil|

  4. #4
    Senior Member k/smaert's Avatar
    Join Date
    Dec 2003
    Posts
    210
    what do you change it to??
    it's defined in milliseconds so you may not notice the changes if they are very small

  5. #5
    graphic designer
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    112
    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
    |calve|brazil|

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center