flash on 2012-4-13

by paulstamp1
♥0 | Line 37 | Modified 2012-04-13 07:50:45 | MIT License
play

ActionScript3 source code

/**
 * Copyright paulstamp1 ( http://wonderfl.net/user/paulstamp1 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/q6Z4
 */

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            //create an instance of a var
            var car:Car = new Car();
            
            //show the car on the screen
            this.addChild( car );
            
            //position the car using cartesian coordinates
            //the top left of the screen is 0,0
            car.x = 150;
            car.y = 150;
        }
    }
}

import flash.display.Sprite;
import flash.geom.Point;

class Car extends Sprite{
        
    private var wheelCollection:Array;
        
    public function Car(){
        
        //store the positions for the wheels in an array
        var wheelPositions:Array = [ new Point(5,35), new Point(75,35), new Point(5,120), new Point(75,120) ];
        
        for( var i:int = 0; i < wheelPositions.length; i++ ){
            var wheel:Wheel = new Wheel();
            var position:Point = wheelPositions[i];
            wheel.x = position.x;
            wheel.y = position.y;
            this.addChild( wheel );
        }
        
        //lets draw our car
        this.graphics.beginFill( 0x0000FF ); //lets make a blue car
        this.graphics.drawRect( 0,0,80,160 );
        this.graphics.endFill(); 
    }
}

class Wheel extends Sprite{
      
      public function Wheel()
      {
          //draw the wheel
          this.graphics.beginFill( 0xFF0000 ); //lets make our wheels red
          this.graphics.drawRect( -10,-20,20,40 );
          this.graphics.endFill();
      }
}