xlandersoftware.com

Xlander Software

How to embed and display an image using FlashDevelop and Haxe

This tutorial will show you how to use FlashDevelop and the Haxe programming language to build a Flash application to display an embedded image.

Step 1:

Import an image into your FlashDevelop project. You can do in one of two ways.

  • Drag an image from Windows Explorer onto the project tree in FlashDevelop.
  • Right click the project tree, select Add, select Existing File and then select an image.

If you have imported the image correctly you will see it listed in the project tree in FlashDevelop as in this picture.

Step 2:

Adding the image to the asset library.

Adding the image to the asset library tells FlashDevelop to embed the asset into the Flash application.

  1. Right click the image in the project tree.
  2. Select Add To Library

If you have successfully added the image to the asset library it will display with blue text in the project tree.

Step 3:

Create an image class.

To be able to access the image Haxe needs a class that extends BitmapData for the embedded image to reference. This is the class you use in your code as a BitmapData object.

  1. Right click your project and select Add, New Class
  2. Name the class FishBitmapData.hx
  3. Declare the class to extends BitmapData
  4. class FishBitmapData extends BitmapData { public function new() { super(0, 0); } }

Step 4:

Reference the image class from the embedded image.

The FishBitmapData class needs to be able to reference the embedded image, this is done by setting the image id in the asset library.

  1. Right click the image in the project tree.
  2. Select Options
  3. Select the Advanced tab
  4. Uncheck the “Auto generate id for attachMovie();” option
  5. Enter a full class name in the text box underneath. “com.xlandersoftware.embeddedimage.FishBitmapData”
  6. Check the embed as Bitmap instead of Clip option.

Step 5:

Create a bitmap.

Create a new Bitmap using the embedded image as the BitmapData and add it to the stage.

var bitmap:Bitmap;
bitmap = new Bitmap(new FishBitmapData(), flash.display.PixelSnapping.ALWAYS, false);
flash.Lib.current.addChild(bitmap);

Leave a Reply

Your email address will not be published.

Proudly powered by WordPress