Many times when creating banners with multiple clickable areas, it’s a pain to do an event listener for each and a function to navigate to that particular URL.
I needed something faster and created a “dead simple” as3 link class, which allows creating as3 links in 1 line. You can download the class and a demo file by clicking the button below.
To use the class from the demo, upload the moonpixel folder to your default class path (more on as3 classpath here >).
Then you can just use it on Buttons, Movie Clips and other Display Objects like so:
var link = new Link(obj:DisplayObject,lnk:String,trgt:String);
Here’s how the class looks, it’s very simple but makes life easier:
package moonpixel.net { import flash.display.DisplayObject; import flash.events.MouseEvent; import flash.net.URLRequest; import flash.net.navigateToURL; public class Link { private var link:String = new String(); private var urlReq:URLRequest; private var target:String = new String(); public function Link(obj:DisplayObject,lnk:String,trgt:String) { obj.addEventListener(MouseEvent.CLICK, golink); link = lnk; target = trgt; } private function golink(e:MouseEvent):void { urlReq = new URLRequest(link); navigateToURL(urlReq,target); } } }
Tags: as3, as3 link class, class, flash, flash as3 links