Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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