Time for action – Using assets
To use an asset, we will have to create a class with the same name as its linkage ID. Depending on the tag we have used, this class should be of a different type as shown in the following table:
Tag |
haXe Type |
---|---|
clip |
|
sound |
|
bitmap |
|
Therefore, for example, for our Ship
we should create the following class:
import flash.display.MovieClip; @:bind class Ship extends MovieClip { public function new() { super(); } }
We can then add an instance of it on our main timeline:
@:bind class TestAssets { public static function main(): Void { var ship = new Ship(); flash.Lib.current.stage.addChild(ship); } }
We will compile and run this as usual, but we need to add an option to our compilation instructions. This option is the -swf-lib
that will instruct the compiler to embed our SWF containing our assets:
-swf-lib assets.swf
It is that simple. Then, compile as...