简体   繁体   中英

Syntax Of Static Constructor in Actionscript-3?

How do I define a static constructor that is run when class is initialized ?

I can't get it right:

// version a:
{}

// version b:
static {}

// version c:
static function Foo()
{}

// version d:
static ()
{}

// version e:
()
{}

// version f:
static function Foo():void
{}

Found it out:

public class Test
{
    public function Test()
    {
        trace("normal constructor");
    }

    // static constructor (version a)
    {
        trace("static constructor");
    }
}

For some reason no question was asked about static constructor in AS-3 ?


Dave suggested, I checked: Actionscript initializers don't even need any syntax:

 public class Test extends Sprite { trace("hello world"); public function Test() { trace("constructor"); } trace("bye world"); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM