Basic AS3 Class Example



This is a simplest example,I hope this will help you to learn as3 and class concept, I love to code and want to share my code with other who want to learn as3 so i am starting a series or tutorials from basic to advanced level

package  
{
	import flash.display.Graphics;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class Ball extends MovieClip
	{
		
		public function Ball() 
		{
			draw()
		}
		
		private function draw():void
		{
			var g:Graphics = graphics;
			g.beginFill(0xff0000, 1);
			g.drawCircle(10, 10, 10);
		}
		
	}

}
In this example we create a class named Ball, which extends MovieClip class, In flash every object which have physical instance must extend MovieClip or Sprite Class,Sprite Class is super class of MovieClip, 

then we get graphics property of MovieClip class

var g:Graphics = graphics;

and then set color to fill

g.beginFill(0xff0000, 1);

then draw a circle on it   

g.drawCircle(10, 10, 10);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s