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

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.