A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Keydown Help

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    2

    Keydown Help

    Hey, very new to flash (Using Flash Pro 8). Currently, I just need to execute a simple show/hide function that is controlled with a key.

    Currently, I have a circle movieclip with this coding attached to it:

    Actionscript Code:
    onClipEvent(keyDown)
    {
      if (Key.isDown(Key.RIGHT))
        _root.circle._visible = true;
    }
    onClipEvent(keyDown)
    {
      if (Key.isDown(Key.RIGHT))
        _root.circle._visible = false;
    }

    and on the first frame of the timeline, I have this code ( so that it is visible = false to begin with ):

    Actionscript Code:
    _root.circle._visible = false;

    Now, my problem is that when pressing the RIGHT key on the keyboard, it reveals the circle, but when it is pressed again, I want it to hide the circle again. Obviously there's a conflict between false and visible, but I don't yet know how to tell flash to make the distinction that the RIGHT key has already been hit once. Is there some kind of 'listener' or something?

    Any help is greatly appreciated! Thank you in advance.

  2. #2
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    Well, first things first; Don't put code on movie clips. For now, since you've got it there we'll go with it. But, in the future if you're going to use more flash and eventually do AS3 you won't/can't put code on clips.

    You need to use a conditional in your keyDown:

    Actionscript Code:
    onClipEvent(keyDown)
    {
      if (Key.isDown(Key.RIGHT)){
        if(_root.circle._visible)
          _root.circle._visible = false;
        else
          _root.circle._visible = true;
      }
    }
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

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