dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Controlling MovieClips

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    3

    Controlling MovieClips

    Fairly inexperienced at anything other than basic scripting in Flash. What I'm trying to do is create a movie clip in AS2 that can be told to play by pressing the spacebar, but only when the mouse is over it. Any help would be appreciated!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    my_mc is the instance name of the movie clip you want to play
    Code:
    keyListener = new Object();
    keyListener.onKeyDown = function() {
            if (Key.getCode() == Key.SPACE) {
                    if (my_mc.hitTest(_xmouse, _ymouse)) {
                            my_mc.play();
                    }
            }
    };
    Key.addListener(keyListener);

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks dawsonk!

    I tried attaching what you typed to the movieclip (chest is the name of my mc):

    Code:
    keyListener = new Object();
    keyListener.onKeyDown = function() {
            if (Key.getCode() == Key.SPACE) {
                    if (chest_mc.hitTest(_xmouse, _ymouse)) {
                            chest_mc.play();
                    }
            }
    };
    Key.addListener(keyListener);
    and I got this error, Statement must appear within on/onClipEvent handler, for each line with a keyListener on it.

    When I attach the code to the frame I get no errors but nothing happens.

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Okay, I got it! I didn't add the _mc to my movie clip name. Thanks dawsonk! I knew it would be a keylistener, but I just couldn't figure out exactly how to code it. This helped a lot!

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