Home > Tutorial > Basic > How to create your own ActionScript 3.0 class?

Why create your own ActionScript 3.0 class?

Using your own classes, you can make programming easier, organize your ActionScript, group related functionality together, and hide details when you don't need to see them.

How to create your own ActionScript 3.0 class?

Suppose the directory of your application is like that:
/Test.fla
/Test.as
/com/FlashExample/MyClass.as
The "Test.as" is an ActionScript 3 document class, and the "MyClass.as" is your own class.

The codes in the "MyClass.as":

package com.FlashExample { public class MyClass{ public function MyClass(){ } public function sayHello():String{ return "Hello"; } } }

Right now, you can import your own class in your document class file. The codes in the "Test.as":

package { import flash.display.*; import com.FlashExample.MyClass; public class Test extends Sprite{ public function Test(){ var myClass:MyClass = new MyClass(); trace(myClass.sayHello()); } } }

Source URL: http://www.flashexample.com/tutorial/how-create-your-own-actionscript-3-class
Published on Flash Example (http://www.flashexample.com), By admin, Created 09/13/2009 - 09:02