Flash AS3 Links Made Easy – AS3 Link Class – Download

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.

[download url=http://docs.moonpixel.com/100718-demo.zip]
[ad]

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);
		}
 
	}
}

Flash AS3 Links Made Easy – AS3 Link Class – Download

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.

[download url=http://docs.moonpixel.com/100718-demo.zip]
[ad]

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);
		}
 
	}
}

Flash – Add Path to Your Classes – AS3 Classpath

When using Flash regularly, as with any other software, there are tasks repeating in many projects over and over again. To speed up this process, it just makes sense creating your own classes and functions and having them available for all projects to use.

So how do we do this?
In order to have a class accessible to all flash projects, we need to add a location (a folder on your computer where you’ll store your classes) to the Source Path.

Go to Flash > Preferences, (this is based on Mac OS X & Flash CS4) and you will get a Preferences window. In the left column select Actionscript.

as3 classpath

At the bottom of the window you will see 2 buttons Actionscript 2.0 Settings and Actionscript 3.0 Settings.
Click on Actionscript 3.0 Settings if you’re using AS3 for your projects.

flash classpath

In the Source Path area click on the “folder” icon (Browse to Path) and locate a folder on your computer where you’ll be storing your classes available to all projects.

as3 source path

And that’s it, now you can use these classes within your projects by importing them like so:

	import moonpixel.net.*;

Which would import all classes within “net” folder which is within “moonpixel” folder which is within your folder you specified in the Source Path.