Classes


Classes

Before AS3 you don’t need thorough knowledge in flash to do animations and interactive presentations. But in case of AS3 the scenario is different. Even if you try to learn it from online tutorials you will certainly be blocked by some barriers knows as classes.

This tutorial is only for beginners in AS3 which will explain the functioning of a simple class.

Create a folder named MyClass anywhere in your computer

Create next folder classes as a subfolder of MyClass

Open Adobe Flash CS3 Professional then create a new Flash file (ActionScript 3) and save it as MyFirstClassFile.fla in your MyClass folder

In file menu select New > ActionScript File

Save it as MyFirstClass in your folder MyClass > classes

Now you can see two tabs named MyFirstClassFile.fla and MyFirstClass.as in your window


Select MyFirstClass.as and type the following

package classes{
public class MyFirstClass {
public function MyFirstClass() {
trace("MyFirstClass is working");
}
}
}


back to MyFirstClassFile.fla and type

import classes.MyFirstClass;
var testYourClass:MyFirstClass = new MyFirstClass();

in actions panel

Test the movie (Press CTRL-Enter)

You should immediately get a message traced to the output window saying “MyFirstClass is working”


Download the source file MyClass.zip

Comments

Popular posts from this blog

AS3 - Access objects from external SWF files

Flash CS3 - XML Guestbook (AS3)

Flash CS4 - 3D Rotating Menu