Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Controlling movie with up and down keys

    Hi,

    Fairly new to Flash and am trying to get a movie to play forward using the 'up' key and play backwards using the 'down' key.

    I have sorted the code so that it works with clicking buttons, but am having problems getting the code right so that it works the same but using keys instead.

    Any suggestions?

    Cheers

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    390

    Default

    Hey,

    please post your code, that will be a lot easier for us to give you hints and find errors

    Regards,
    A.
    hardware is the part of a computer which can be kicked

    Things that NTD thaught me:

    {An optimist sees the glass as half full. A pessimest sees the glass as half empty.
    A programmer sees the glass as twice the size it needs to be.}


    Please no questions via private and / or instant message!


  4. #3

    Default

    Hi,

    This is the code that's on my back button

    on (press) {
    _root.control.gotoAndPlay(2);
    }
    on (release) {
    _root.control.gotoAndPlay(1);
    }

    This goes to a movie clip to control the looping backwards.

    On the forwards button, simply:

    on (press) {
    play();
    }
    on (release) {
    stop();
    }

    I had hoped that it would be simple to replace button commands with keyboard commands, but having researched it, I'm struggling making sense of the variety of keyboard input options and which are appropriate.

    I gather that having a bunch of code together that involves key listeners and 'if' and 'else' code may be the way, but am not sure if this code needs to be attached to anything (movie or button off screen).

    I appreciate the help.

    Cheers

  5. #4
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    Key motion function...
    Code:
    /*
    Key Motion Function
    T. Norman
    http://ntdesigns.net
    */
    function keyMoveTarget(targetName, speed) {
    	speed = speed;
    	this.onEnterFrame = function() {
    		//Motion
    		/*
    		code for other than standard keys...
    		if (Key.getCode() == 87) {
    		targetName._y -= speed;
    		trace("you typed the key");
    		} else if (Key.getCode() == 83) {
    		targetName._y += speed;
    		} else if (Key.getCode() == 65) {
    		targetName._x -= speed;
    		} else if (Key.getCode() == 68) {
    		targetName._x += speed;
    		}
    		*/
    		if (Key.isDown(Key.UP)) {
    			targetName._y -= speed;
    		} else if (Key.isDown(Key.DOWN)) {
    			targetName._y += speed;
    		} else if (Key.isDown(Key.LEFT)) {
    			targetName._x -= speed;
    		} else if (Key.isDown(Key.RIGHT)) {
    			targetName._x += speed;
    		}
    		//Boundary    
    		if (targetName._x>Stage.width) {
    			targetName._x = Stage.width;
    		} else if (targetName._x<0) {
    			targetName._x = 0;
    		} else if (targetName._y>Stage.height) {
    			targetName._y = Stage.height;
    		} else if (targetName._y<0) {
    			targetName._y = 0;
    		}
    	};
    }
    keyMoveTarget(ball, 10);
    hope it helps
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial