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.
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.
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)); flash.Lib.current.addChild(sprite);
Bind the sprite’s on click event to a function.
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
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");