Flash Develop for Flash Player 11 compilation

first download flash develop and flex sdk and flash player and playerglobal.swc

now extract flexsdk in your hard drive and paste playerglobal.swc in “frameworks\libs\player\11.0\”

Install Flash develop by double clicking its exe file,

Create new project,

Go to Project>Properties>Output>Platform. Change Target to Flash Player 11.0.
In Project>Properties>Compiler Options >advanced, change Additional Compiler Options to “-swf-version=13” (without quotes)

Go to Project>Properties>Output>Test Movie. Select Open document from dropdown list. Click Edit button and type “bin\index.html” (without quotes)

now edit bin\index.html and change wmode to “direct”. for more detail click this link.

Flash player 11 cubicCurveTo Example

package  
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Jeetendra Singh
	 */
	public class Main extends Sprite
	{
		private var control1:Sprite;
		private var control2:Sprite;
		
		public function Main() 
		{
			init();
		}
		
		private function init():void 
		{
			control1 = new Circle(); 
			control2 = new Circle();
			addChild(control1);
			addChild(control2);
			control1.x = 500;
			control1.y = 500;
			control2.x = 500;
			control2.y = 100;
			control1.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			control2.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			
			addEventListener(Event.ENTER_FRAME, render);
		}
		
		private function onMouseDown(e:MouseEvent):void 
		{
			Sprite(e.target).addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			Sprite(e.target).removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			Sprite(e.target).startDrag();
		}
		
		private function onMouseUp(e:MouseEvent):void 
		{
			Sprite(e.target).removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			Sprite(e.target).addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			Sprite(e.target).stopDrag();
		}
		
		
		
		private function render(e:Event):void 
		{
			var g:Graphics = this.graphics;
			g.clear();
			g.lineStyle(2, 0xff0000);
			g.moveTo(200, 200);
			g.cubicCurveTo(control1.x, control1.y, control2.x, control2.y, 400, 30);
		}
		
	}

}
// Helper Class
import flash.display.Sprite;
class Circle extends Sprite 
{
	public function Circle() 
	{
		this.graphics.beginFill(0xff00ff, 1);
		this.graphics.drawCircle(0, 0, 10);
	}
}

integer comparision with NaN

Hi,
You may be shocked while comparing a integer variable with NaN like this because default value of a integer is 0

var a:int;

if(a == NaN)
{
// code when a is not initilize
}

This will not provide desired result.


var a:int;
if(isNaN(a))
{
// code when a is not initilize
}

This will also not provide desired result.

Try this code

var a:int;
trace(a);//0
a = 10;
trace(a)//10
a = undefined;
trace(a)//0

Moral of the story: Integer number does not have NaN.

for more info see lukasz comment below

Moving balls

I did change in my previous example and make Balls moveable
  
 
  
 package 
  
 {
  
     import flash.display.Graphics;
  
     import flash.display.MovieClip;
  
     /**
  
      * ...
  
      * @author Jeet Chauhan
  
      */
  
     public class BallWithParameter extends MovieClip
  
     {
  
         
  
         private var color:uint;
  
         private var radius:Number;
  
         
  
         public function BallWithParameter(radius:Number = 10,color:uint=0xffff00) 
  
         {
  
             this.color = color;
  
             this.radius = radius;
  
             draw()
  
         }
  
         
  
         private function draw():void
  
         {
  
             var g:Graphics = graphics;
  
             g.beginFill(color, 1);
  
             g.drawCircle(0, 0, radius);
  
         }
  
         /**
  
          * this will set position of current instance
  
          * @param    dx
  
          * @param    dy
  
          */
  
         public function setPosition(dx:Number, dy:Number):void
  
         {
  
             this.x = dx;
  
             this.y = dy;
  
         }
  
         
  
         /**
  
          * this will move current instance 
  
          * @param    dx
  
          * @param    dy
  
          */
  
         public function moveBy(dx:Number, dy:Number):void
  
         {
  
             this.x += dx;
  
             this.y += dy;
  
         }
  
         
  
     }
  
 
  
 }
  
 
  
 
  
 
  
 package 
  
 {
  
     import flash.display.MovieClip;
  
     import flash.events.Event;
  
     
  
     /**
  
      * ...
  
      * @author Jeet Chauhan
  
      */
  
     public class MultipleBall extends MovieClip
  
     {
  
         private var balls:Array;
  
         public function MultipleBall() 
  
         {
  
             draw()
  
         }
  
         
  
         private function draw():void
  
         {
  
             balls = new Array();
  
             for (var i:int = 0; i < 100; i++) 
  
             {
  
                 var ball:BallWithParameter = new BallWithParameter(Math.random() * 5 + 5, Math.random() * 0xffffff);
  
                 balls.push(ball);
  
                 //ball.setPosition(Math.random() * stage.stageWidth,Math.random() * stage.stageHeight)
  
                 ball.x = Math.random() * stage.stageWidth;
  
                 ball.y = Math.random() * stage.stageHeight;
  
                 addChild(ball);
  
             }
  
             stage.addEventListener(Event.ENTER_FRAME, animate);
  
         }
  
         
  
         private function animate(e:Event):void 
  
         {
  
             for (var i:int = 0; i < 100; i++) 
  
             {
  
                 BallWithParameter(balls[i]).moveBy(Math.random() * 10 - 5, Math.random() * 10 - 5);
  
             }
  
         }
  
         
  
     }
  
 
  
 }  

Second Class


This is improved version of previous post this is more reusable then previous post.
package  
{
	import flash.display.Graphics;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class BallWithParameter extends MovieClip
	{
		private var color:uint;
		private var radius:Number;
		
		public function BallWithParameter(radius:Number = 10,color:uint=0xffff00) 
		{
			this.color = color;
			this.radius = radius;
			draw()
		}
		
		private function draw():void
		{
			var g:Graphics = graphics;
			g.beginFill(color, 1);
			g.drawCircle(0, 0, radius);
		}
		
	}

}

This class initilize random color and radius ball use it as a document class

package  
{
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class MultipleBall extends MovieClip
	{
		
		public function MultipleBall() 
		{
			draw()
		}
		
		private function draw():void
		{
			var ball:BallWithParameter = new BallWithParameter(Math.random() * 5 + 5, Math.random() * 0xffffff);
			ball.x = Math.random() * stage.stageWidth;
			ball.y = Math.random() * stage.stageHeight;
			addChild(ball);
		}
		
	}

}

this will create multiple circles

package  
{
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class MultipleBall extends MovieClip
	{
		
		public function MultipleBall() 
		{
			draw()
		}
		
		private function draw():void
		{
			for (var i:int = 0; i < 100; i++) 
			{
				var ball:BallWithParameter = new BallWithParameter(Math.random() * 5 + 5, Math.random() * 0xffffff);
				ball.x = Math.random() * stage.stageWidth;
				ball.y = Math.random() * stage.stageHeight;
				addChild(ball);
			}
			
		}
		
	}

}

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);

create dynamic line using graphics class

This class simply create a line using Graphics class lineTo and moveTo methods hope this will help someone


package 
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class drawLine extends Sprite 
	{
		// variable to hold graphics class instanve
		private var g:Graphics;
		
		public function drawLine():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			g = graphics
			// this will set line thickness from 1 to 4 and a random color
			g.lineStyle(int(Math.random() * 3) + 1, Math.random() * 0xff0000);
			// this will moves the current drawing position to (50,50)
			g.moveTo(50, 50);
			draw();
		}
		
		private function draw():void
		{
			//Draws a line from the current drawing position to (500, 500).
			g.lineTo(500, 500);
		}
		
	}
	
}

as3 increment and decrement operator

What will be the result of snippet in AS3 ,Guess?

var a:int = 1;
a = ++a + a++ + a;
a = a– + –a;
a = ?

Solution

var a:int = 1;
// a == 1
a = ++a + a++ + a;
// ++a is pre increment operator(first increment then assignment) and a++ is post increment operator(first assignment then increment) as3 compiler parse left to right so first ++a then a++ and finally a so result become
// 2 + 2 + 3 = 7

a = a– + –a;
// a– is post decrement operator and –a is pre decrement operator
// 7 + 5 = 12

a = ? // 12

there is a Gotcha ,if you use c concept then you will give wrong answer, because as3 parse From left to right (opposite to c language)
if have any confusion please comment i will try to answer