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

Closed Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1

    Default Off screen movement

    I have made small game, but my animation is going out of the dcreen when I move it. Can somebody please give me the code how can I stop the animation when it riches the end of the screen.

    This is the code that I have in my game:

    Code:
    function moveHeli(speed) {
    	if (Key.isDown(Key.UP)) {
    		_root.longbow._y -= speed;
    	} else if (Key.isDown(Key.LEFT)) {
    		_root.longbow._x -= speed;
    	} else if (Key.isDown(Key.DOWN)) {
    		_root.longbow._y += speed;
    	} else if (Key.isDown(Key.RIGHT)) {
    		_root.longbow._x += speed;
    }
    }
    _root.onEnterFrame = function() {
    	moveHeli(5);
    then I have try with this, but I don't know how to finish...:

    Code:
    stage_x = 550;
    stage_y = 650;
    hero_x = getProperty("longbow", _width);
    hero_y = getProperty("longbow", _height);
    function moveHeli(speed) {
    	if (Key.isDown(Key.UP)) {
    		_root.longbow._y -= speed;
    	} else if (Key.isDown(Key.LEFT)) {
    		_root.longbow._x -= speed;
    	} else if (Key.isDown(Key.DOWN)) {
    		_root.longbow._y += speed;
    	} else if (Key.isDown(Key.RIGHT)) {
    		_root.longbow._x += speed;
    }
    }
    _root.onEnterFrame = function() {
    	moveHeli(5);

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    Simple boundary check function. Paste the function onto the first frame of your movie and pass it the instance name of the targetMC you want the boundary set for........

    Code:
    function checkBoundary(myTarget) {
    	this.onEnterFrame = function() {
    		if (myTarget._x>Stage.width) {
    			myTarget._x = 0;
    		&#125; else if &#40;myTarget._x<0&#41; &#123;
    			myTarget._x = Stage.width;
    		&#125; else if &#40;myTarget._y>Stage.height&#41; &#123;
    			myTarget._y = 0;
    		&#125; else if &#40;myTarget._y<0&#41; &#123;
    			myTarget._y = Stage.height;
    		&#125;
    	&#125;
    &#125;
    //Usage
    checkBoundary&#40;_root.mcInstanceName&#41;;
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  4. #3

    Default

    THANKS NTD!!!!


  5. #4

    Default

    Quote Originally Posted by NTD
    Hi,

    Simple boundary check function. Paste the function onto the first frame of your movie and pass it the instance name of the targetMC you want the boundary set for........

    Code:
    function checkBoundary&#40;myTarget&#41; &#123;
    	this.onEnterFrame = function&#40;&#41; &#123;
    		if &#40;myTarget._x>Stage.width&#41; &#123;
    			myTarget._x = 0;
    		&#125; else if &#40;myTarget._x<0&#41; &#123;
    			myTarget._x = Stage.width;
    		&#125; else if &#40;myTarget._y>Stage.height&#41; &#123;
    			myTarget._y = 0;
    		&#125; else if &#40;myTarget._y<0&#41; &#123;
    			myTarget._y = Stage.height;
    		&#125;
    	&#125;
    &#125;
    //Usage
    checkBoundary&#40;_root.mcInstanceName&#41;;
    I didn't do something good here.

    I have animation with name longbow (that animation can't go out of the screen) label name is longbow. This is the code that I have insert but it doesn'd do, what did I do wrong?

    Code:
    stop&#40;&#41;;
    function checkBoundary&#40;longbow&#41; &#123; 
       this.onEnterFrame = function&#40;&#41; &#123; 
          if &#40;longbow._x>Stage.width&#41; &#123; 
             longbow._x = 0; 
          &#125; else if &#40;longbow._x<0&#41; &#123; 
             longbow._x = Stage.width; 
          &#125; else if &#40;longbow._y>Stage.height&#41; &#123; 
             longbow._y = 0; 
          &#125; else if &#40;longbow._y<0&#41; &#123; 
             longbow._y = Stage.height; 
          &#125; 
       &#125; 
    &#125; 
    //Usage 
    checkBoundary&#40;_root.longbow&#41;;

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

    Default

    Hi,

    You dont need to change anything in the function. I coded it so it is very easy to use All you need to do is pass the instance name of the target clip that you want to set the boundary for to the function.......

    Code:
    function checkBoundary&#40;myTarget&#41; &#123; 
       this.onEnterFrame = function&#40;&#41; &#123; 
          if &#40;myTarget._x>Stage.width&#41; &#123; 
             myTarget._x = 0; 
          &#125; else if &#40;myTarget._x<0&#41; &#123; 
             myTarget._x = Stage.width; 
          &#125; else if &#40;myTarget._y>Stage.height&#41; &#123; 
             myTarget._y = 0; 
          &#125; else if &#40;myTarget._y<0&#41; &#123; 
             myTarget._y = Stage.height; 
          &#125; 
       &#125; 
    &#125; 
    //Usage 
    checkBoundary&#40;_root.longbow&#41;;
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  7. #6

    Default

    OK, now I understand. But I have inserted and still nothing. My mc (animation) is in layer one and the actions script is in frame two. In this action scritp there is function for moving longbow and function that you have gave me.

    Like this:

    Code:
    stop&#40;&#41;;
    function checkBoundary&#40;myTarget&#41; &#123; 
       this.onEnterFrame = function&#40;&#41; &#123; 
          if &#40;myTarget._x>Stage.width&#41; &#123; 
             myTarget._x = 0; 
          &#125; else if &#40;myTarget._x<0&#41; &#123; 
             myTarget._x = Stage.width; 
          &#125; else if &#40;myTarget._y>Stage.height&#41; &#123; 
             myTarget._y = 0; 
          &#125; else if &#40;myTarget._y<0&#41; &#123; 
             myTarget._y = Stage.height; 
          &#125; 
       &#125; 
    &#125; 
    //Usage 
    checkBoundary&#40;_root.longbow&#41;;
    
    function moveHeli&#40;speed&#41; &#123;
    	
    	if &#40;Key.isDown&#40;Key.UP&#41;&#41; &#123;
    		_root.longbow._y -= speed;
    	&#125; else if &#40;Key.isDown&#40;Key.LEFT&#41;&#41; &#123;
    		_root.longbow._x -= speed;
    	&#125; else if &#40;Key.isDown&#40;Key.DOWN&#41;&#41; &#123;
    		_root.longbow._y += speed;
    	&#125; else if &#40;Key.isDown&#40;Key.RIGHT&#41;&#41; &#123;
    		_root.longbow._x += speed;
    	&#125;	
    &#125;
    _root.onEnterFrame = function&#40;&#41; &#123;
    	moveHeli&#40;5&#41;;
    &#125;;
    Nothing. When I insert your code after "moving" function, I can't move my longbow...

    Look, NTD, I am sorry to giving you such a deal and work for nothing, but I am new in this and I would really like to learn flash. People like you (with such expiriance) are my only help...

  8. #7
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    My mc (animation) is in layer one and the actions script is in frame two.
    Actions should reside on the first frame of your movie. It is generally standard practice to create a layer above all other content and paste actionscript to it's own individual layer. The span on the timeline for the actionscript should span the length of any layers underneath.
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  9. #8

    Default

    Quote Originally Posted by Um
    My mc (animation) is in layer one and the actions script is in frame two.
    Sorry, I didn't say well. Bouth of them are in frame 116, but animation (longbow) is in layer 2 (up) and script is in layer 1 (down). Before 116 frame there is preloader, then short intro and menu with play, instructions and exit.
    So when your press play button the game start on 116 frame.
    Hope that this is Ok, my longbow animation moves and everything is OK, but the script for "not-going-off-the-screen" (script is like I posted before) doesn't do anything.

    I try to insert it on frame 2, but then longbow animation wonts move at all.
    I think that "move-code" and "not-going-off-the-screen" action scripts must be on 116 frame, but only problem is why doesnt your code function there...
    Hm, some times I feel like idiot, I am very ashamed now, you must be thinking:"Oh, comeon, if you cant do this, leave it..", but every start is difficult.

    You help me and maybe I can help you in something other if you are interested in... For example, how to make themes and skins for SonyEricsson P800/P900/P910i or any other SonyEricsson model...

  10. #9

    Default

    This is the code that I have insert now. And it works, but works really strange.
    When my heli (longbow) is totaly out of the screen he comes back from other side, I wont that my heli stops right when he reach to the end of the stage.

    Code:
    stop&#40;&#41;;
    function moveHeli&#40;speed&#41; &#123;
    	
    	if &#40;Key.isDown&#40;Key.UP&#41;&#41; &#123;
    		_root.longbow._y -= speed;
    	&#125; else if &#40;Key.isDown&#40;Key.LEFT&#41;&#41; &#123;
    		_root.longbow._x -= speed;
    	&#125; else if &#40;Key.isDown&#40;Key.DOWN&#41;&#41; &#123;
    		_root.longbow._y += speed;
    	&#125; else if &#40;Key.isDown&#40;Key.RIGHT&#41;&#41; &#123;
    		_root.longbow._x += speed;
    	  &#125; else if &#40;longbow._x>Stage.width&#41; &#123; 
             longbow._x = 0; 
          &#125; else if &#40;longbow._x<0&#41; &#123; 
             longbow._x = Stage.width; 
          &#125; else if &#40;longbow._y>Stage.height&#41; &#123; 
             longbow._y = 0; 
          &#125; else if &#40;longbow._y<0&#41; &#123; 
             longbow._y = Stage.height; 
          &#125; 
       &#125; 
    _root.onEnterFrame = function&#40;&#41; &#123;
    	moveHeli&#40;5&#41;;
    &#125;;
    Also, when I insert the game on the web, my heli (longbow) doesn't move at all, but on my comp it move...

    Here is the game that I have insert to try how it works on web, you'll see that heli doesn't move...

    http://www.um-design.com/Longbow/Longbow.html

  11. #10
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    The motion works, you just need to make sure the page is in focus. Click on the screen and the motion works. Try adding the full path to the movieclip in the boundary check. The same as you have it for the motion.....

    _root.longbow..........instead of just longbow
    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)

     

Similar Threads

  1. Movement - Firing a bullet..
    By iamali in forum Flash Scripting
    Replies: 2
    Last Post: 11-12-2006, 03:46 PM
  2. pong collisions and movement
    By weefolk in forum Flash Scripting
    Replies: 1
    Last Post: 05-19-2006, 04:06 PM
  3. movement question and www.thekooks.co.uk
    By auejim in forum Advanced Flash
    Replies: 19
    Last Post: 05-13-2006, 09:59 PM
  4. Need help with Character movement
    By lewmiszkin in forum Games
    Replies: 0
    Last Post: 12-14-2005, 05:37 AM
  5. need help with mouse over movement
    By domenique in forum Advanced Flash
    Replies: 3
    Last Post: 07-13-2005, 06:00 PM

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