Xlander Software

How to open a URL by clicking an image in Flash using FlashDevelop and Haxe

This tutorial will show you how to use FlashDevelop and Haxe to build a Flash application that can open a URL by clicking on an image.

Step 1:
Embed an image into the FlashDevelop project.
I have written a tutorial on how to do this here: Embed an image with Haxe and FlashDevelop tutorial.

Step 2:
Wrap the bitmap in a sprite.

A bitmap will not respond to a mouse click event. The simple solution to this is to create a sprite and add the bitmap as a child of the sprite.

var sprite:Sprite;
sprite = new Sprite();
sprite.addChild(new Bitmap(new ExampleBitmapData(),
    flash.display.PixelSnapping.AUTO, false));

Step 3:
Bind the sprite’s on click event to a function.

sprite.addEventListener(MouseEvent.CLICK, SpriteClicked);

Step 3:
Handle the sprite clicked event.

For the sprite MouseEvent.Click to be handled you will need an event handler with the following signature.

function SpriteClicked(event:MouseEvent) : Void

Step 4:
Open the url on click.

Now that the sprite has a function bound to it’s mouse click event we can simply open a url in the event handler function. Haxe has a library function for opening url’s called getURL. It takes a URLRequest object as an argument.

Here is a simple example of opening a url.

flash.Lib.getURL(new URLRequest("http://xlandersoftware.com"), "_blank");

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress