RSS link icon

.

html linkbutton with actionscript 3


In this flash tutorial you will see how to through code, dynamically create a text link in flash and give it an event when its clicked. If this sounds complicated, just take a look below, its quite simple, even though AS3 is still a bit different the the pervious version and I am still learning.

This flash example we are going to make does not require much visual work on the stage, the only thing we need is to make a text field so grab the text tool and drag a text field on the stage, go to the properties panel and make it a dynamic text field (so it can receive input). Then give it an instance name, I named mine message_ (not message because that word is reserved by flash code).

link in flash

Now everything else is done by code, so open up the flash action script panel and type in the following code, I made some description in between the code to make it more understandable.

//First we declare our textfield object so it exists in flash.
var thelink:TextField = new TextField();

//Now we give the text field a value to show and as we use the htmltext
//it renders the content as html code, (quite a nice feature I think).
//An inportant thing to notice here is the event:you clicked it. this,
//this is the event that will be raised when the link is clicked.
thelink.htmlText = 'Click here';

//here we add the link to the main stage (of cause if you want to add it
//else where, just refere to the position (eg. movieclip.addChild(thelink).
addChild(thelink);

//These two lines is just to place the link somewhere on the stage and not in position 0,0.
thelink.x = 50;
thelink.y = 20;

//And we are working in AS3 so we need to add an eventlistener to tell flash to listen to,
//if the link is clicked.
thelink.addEventListener(TextEvent.LINK, linkEvent);

//And here is the function to "run" the event, it bascilly just says to wirte the event text
//in our text field which we named "message_"
function linkEvent(event:TextEvent):void {
	message_.text = event.text
}

yoyo says: 2008-07-25

good and a nice tutorial

Satyanarayana Tadepalli says: 2008-03-28

nice tutorial with the interfaceing
make money with photoshop - book