Tuesday, October 2, 2012

Import ActionScript 3 external class to Flash CS5

Suppose you have flash file myflash.fla in
and you have Main class in:
Main.as is as follows:
package com.example
    public class Main extends Sprite
        public function Main():void

There are two ways to call Main class in Flash CS5.
 1) In Flash CS5, File->ActionScript setting-> document class, input Main
2) Press F9, import the following script:
var test:Main = new Main();
There is some difference between method 1) and method 2
If stage.stageWidth is used in the script, the method 1 is recommended. The method 2 will return the following error message:
Error #1009: Cannot access a property or method of a null object reference.

No comments:

Post a Comment