A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: When upleftdown arrowkeys are pushed down = frame 2, downkey = frame 3, else frame 1?

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    119

    When upleftdown arrowkeys are pushed down = frame 2, downkey = frame 3, else frame 1?

    I feel like it should be a simple script but i cant seem to get it right,
    I have a movieclip with Three frames. Im looking for a script that when the up/left/right are pushed down (and kept down) in any combination the movieclip goes to frame 2. When the down Arrowkey is pressed it goes to fram 3. If no button is pushed down the movieclip goes back to frame 1

    How would such a script look? Thanks in advance!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You could make something of this, there are probably a few ways of achieving this, but this off the head.
    PHP Code:
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function()
    {
        if (
    Key.isDown(Key.DOWN))
        {
            
    //gotoAndStop(2);
            
    trace("D");
        }

        if (
    Key.isDown(Key.UP) && Key.isDown(Key.LEFT) && Key.isDown(Key.RIGHT))
        {
            
    //gotoAndStop(3);
            
    trace("L R U");
        }
    };
    keyListener.onKeyUp = function()
    {
        if (!
    Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.DOWN))
        {
            
    //gotoAndStop(1);
            
    trace("None");
        }
    };
    Key.addListener(keyListener); 

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Posts
    119
    Thanks (and for fixing the movement problem in my previous post )
    Where do i put this code in the context of my .fla?
    Attached Files Attached Files

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Try putting the above code on the first frame of the timeline and test it, see if works how you desire, then mess around with it.

  5. #5
    Junior Member
    Join Date
    Feb 2015
    Posts
    1
    Thanks for the code, I was also looking for a script like this.

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