开发者

Create Main class in AS2?

开发者 https://www.devze.com 2023-03-29 09:55 出处:网络
I know that in AS3 I can create a Main class and link it to the FLA file. I tried doing the same in AS2 but couldn\'t. (When I try linking the fla to a class, it says the featur开发者_运维问答e only e

I know that in AS3 I can create a Main class and link it to the FLA file. I tried doing the same in AS2 but couldn't. (When I try linking the fla to a class, it says the featur开发者_运维问答e only exists in AS3)

Can I link the FLA to a class in some other way? If this is not possible, how would you suggest I perform actions when the file is loaded (and, in this case, define an ExternalInterface)?

Thank you.


here is the approach i would use. you define a static method in your 'document' class and then pass in the reference to your main timeline at runtime:

class MyClass extends MovieClip
{
    public static function main(target:MovieClip):Void
    {
        target.__proto__ = MyClass.prototype;
        target.init();
    }

    private function init():Void
    {
       // your construction code....
    }
}

Then in your FLA, on the first frame, invoke the class's static 'main' and pass it the main timeline movieclip as the argurment. this is kinda like wrapping the timline with your document class.

MyClass.main(this);

Example based on http://www.bit-101.com/blog/?p=857. i just added it here to fix up the broken code tags on his site.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号