Skip to content


[AS 3] Text Links calling Actionscript Functions

In this demo I have utilized the Button and the Yahoo! AlertManager component. I simply created a textfield in the upper left corner with an html anchor tag that calls a function within the Actionscript code.

Here is my Document Class file TextHTMLLinks.as:

package
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.events.TextEvent;
	import com.yahoo.astra.fl.managers.AlertManager;
    import fl.events.ComponentEvent;
	import flash.events.MouseEvent;

	public class TextHTMLLinks extends Sprite
	{
		private var myFormat:TextFormat;
		private var myTextField:TextField;

		public function TextHTMLLinks():void
		{
			// format the text
			var myFormat:TextFormat = new TextFormat();
			myFormat.size = 16;
			myFormat.font = "Arial";
			myFormat.color = 0xffffff;

			// create the text field and add the link
			var myTextField:TextField = new TextField();
			myTextField.autoSize = TextFieldAutoSize.LEFT;
			myTextField.multiline = true;
			myTextField.defaultTextFormat = myFormat;
			myTextField.htmlText = "

Here is my title

";
			myTextField.htmlText += "

Click here for the alert box

";

			// add the listener for the link
			myTextField.addEventListener(TextEvent.LINK, clickLink);

			// add the object to the stage
			addChild(myTextField);
		}

		private function clickLink(e:TextEvent):void
		{
			if (e.text == "alert")
			{
				AlertManager.createAlert(this, "Here is my message", "My Title: Alert Box",["close alert"]);
			}
		}
	}

}

Posted in Actionscript 3, Flash Text / HTML / CSS.


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Srihari.Ch says

    How to create pop-up n ACtionScript?

    Actually, What I need is:
    Whenever I click on an object (or) part of an object, it should get some text/info displayed in a pop-up.

  2. Alexwebmaster says

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru



Some HTML is OK

or, reply to this post via trackback.