Archive

Archive for March, 2010

Animate with Enter_Frame event in AS3

March 25, 2010 Leave a comment

Hi folks, in this post i’m going to show how to animate an object by using Enter_Frame in as3.

Beside commonly used tween class, or third party tweener Enter_Frame event constantly triggering according to the frame of the fla file per second.

In this post i created a Main document class and a circle class as the example, every time you click the circle the circle will move 200 in x-axis;

circle class:

package
{

import flash.display.Sprite;
import flash.events.*;

public class Circle extends Sprite
{
public function Circle()
{
this.addEventListener(MouseEvent.CLICK, movecircle);

}
function movecircle(e:MouseEvent)
{

this.addEventListener(Event.ENTER_FRAME, circleframe);

}
function circleframe(e:Event)
{
var i:int
this.x=this.x+10;

for (i=0; i<10; i++)
{

if(this.x == 200*i)
{
this.removeEventListener(Event.ENTER_FRAME, circleframe);

}
}
}

}
}

2. Main Document Class

package
{
import flash.display.MovieClip;

public class Main extends MovieClip
{
var circle:Circle = new Circle();
public function Main()
{
circle.x= 150;
addChild(circle);

}

}
}

As you can see what i’m done here, i just created an sweet little handy event handler called circleframe like any other events and execute the method

this.addEventListener(Event.ENTER_FRAME, circleframe);

along with its function:

function circleframe(e:Event)
{
var i:int
this.x=this.x+10;

for (i=0; i<10; i++)
{

if(this.x == 200*i)
{
this.removeEventListener(Event.ENTER_FRAME, circleframe);

}

If you want to stop it just remove it by using any condition.

As you test the movie the first click the circle only moved  50 in x-axis this is because we initiated the circle at 150 x position at the main document class.

Categories: Uncategorized

2 ways to instantiate and link document class in AS3

March 11, 2010 Leave a comment

ok folks, today i’m going show you 2 ways to link class in as3

Method 1: Instantiating in AS file and link from Document class
Method 2: Instantiating in fla’s file main time line

Method 1: Instantiating in AS file and link from Document class

On the new fla file make sure the name of the Document class ‘s name is same with the AS file class you’ve created, be note  that class name must be same with the AS file name. By using this way every object has to be instantiate in the as file.

Method 2: Instantiating in fla’s file main time line

This method will be using time line to instantiate the object in the AS file,  first create the class with its method but remember don’t link the Document class in FLA file with the AS file class,or you will get error, instead of that you have to make it on the time line.

is easy for example

first you create you class like normally you create but you don’t have to import flash classes.  because we’ll instantiate directly to the FLA’s time line. but how to link it you said? easy

just instantiate on the main time line with the ‘new’ keyword:

for expample-   var yourval:classname = new classname();

That’s it simple and easy hope you enjoy.

Categories: Uncategorized

scaleMode in AS2 and AS3

March 8, 2010 1 comment

There is abit little change on Scale mode in as3

In as2:

Stage.scaleMode = “noScale”;

In as3:

stage.scaleMode = StageScaleMode.NO_SCALE;

and remember to import the scale mode class in order to make it works

import flash.display.StageScaleMode;

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.