O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

flash.display.MovieClip

sound

flash.display.MovieClip

bitmap

flash.display.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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required