Skip to content


Events from Text Links in a Textfield

I wanted to know if I had the ability to call a function from within Flash from a text link inside a text field. I was able to find a solution with from the TextEvent class.

With this basic demo if you click either Test 1, Test 2, .., Test 5 – the results from the click will appear to the right.

package {
    import flash.display.Sprite;
    import flash.errors.IOError;
    import flash.events.IOErrorEvent;
    import flash.events.TextEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class TextfieldEvent extends Sprite
    {
		private var outTxt:TextField;

        public function TextfieldEvent()
		{
            var list:TextField = new TextField();
            list.autoSize = TextFieldAutoSize.LEFT;
            list.multiline = true;
            list.htmlText = "Test 1";
            list.htmlText += "Test 2";
			list.htmlText += "Test 3";
			list.htmlText += "Test 4";
			list.htmlText += "Test 5";
            addEventListener(TextEvent.LINK, linkHandler);
            addChild(list);

			outTxt = new TextField();
            outTxt.autoSize = TextFieldAutoSize.LEFT;
            outTxt.multiline = true;
			outTxt.x = 300;
			addChild(outTxt);
        }

        private function linkHandler(linkEvent:TextEvent):void
		{
            outTxt.htmlText += linkEvent.text;
        }
    }
}

Damn editor! Anyways, below is a screenshot of the corrected area:

Posted in Actionscript 3.


0 Responses

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



Some HTML is OK

or, reply to this post via trackback.