A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Moving movieclip from left to right with actionscript

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Posts
    19

    Moving movieclip from left to right with actionscript

    Hi guys,

    Basically I need to have a cartoon character walking to the right hand side of the screen and then turning around and moving back to the left hand side and so on.

    Does any one know ne good tutorials for this?

    I have some code done but it could be all wrong as I am not the best coder at all, just starting out.
    I will attach the code I have.

    Code:
    package classes
    {
    	import flash.display.MovieClip;
    	import classes.RollableChar;
    
    	
    	public class MainApp2 extends MovieClip
    	{
    		//public var theCharacter:MovieClip;
    		//public var myCarrot:RollableChar; 
    		
    		public function MainApp2()
    		{
    			roll();
    			//trace("Hello");
    		}
    		
    		private function roll()
    		{
    
    		}
    		
    		
    	}
    	
    }

    Code:
    package classes
    {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.display.MovieClip;
    	import flash.events.MouseEvent;
    
    	
    	public class RollableChar extends MovieClip
    	{
    		
    		//static const edgeDistance:Number = 80;
    		private var character:MovieClip;
    		public var theCharacter:MovieClip;
    		
    		public function startChar() {
    			
    			// add to screen characters
    			addCharacter();
    			
    			
    		}
    		
    		public function addCharacter() {
    				
    				var character = new Object();
    				theCharacter.dx = 0.0;
    				theCharacter.x = 100;
    				theCharacter.dy = 100;
    				theCharacter.direction = 1;
    				theCharacter.moveRight = true;
    				theCharacter.moveLeft = true;
    				theCharacter.rollSpeed = 10;
    				
    				if ((theCharacter.dx < 0) && (theCharacter.x > 100)) {
    				addCharacter(); }
    			}
    			
    			public function sit() {
    				
    			}
    		
    		
    		public function roll(charcter:MovieClip) {
    			for(var i:int=0;i<character.length;i++) {
    				
    				// move
    				roll(character[i]);
    				
    				// if hit a wall, turn around
    				if (character[i].hitWallRight) {
    					character[i].moveLeft = true;
    					character[i].moveRight = false;
    				} else if (character[i].hitWallLeft) {
    					character[i].moveLeft = false;
    					character[i].moveRight = true;
    				}
    			}
    		}
    
    		
    	}
    }

  2. #2
    Junior Member
    Join Date
    Jun 2007
    Posts
    19
    Sorted

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