AS3: TextEvent.LINK and ContextMenu incompatibilities.
Monday, July 23rd, 2007 by LuisThis morning I run into a small problem when using the new TextEvent.LINK.
Basically as with ActionScript 1 and ActionScript 2, ActionScript 3 allows you to associate ActionScript events with links in a textfield.
In AS3, the LINK event is dispatched when a user clicks a hyperlink in an HTML-enabled text field, where the URL begins with "event:". The remainder of the URL after "event:" will be placed in the text property of the LINK event.
Everything is good until here, but the problem comes when you right-click the link in the textfield. By default the flash player shows one type of context menu that is not any of the 3 types defined in the docs.

According with the AS3 language reference the Flash Player has three types of context menus: the standard menu (which appears when you right-click in Flash Player), the edit menu (which appears when you right-click a selectable or editable text field), and an error menu (which appears when a SWF file has failed to load into Flash Player).
The problem with the context menu appearing when you right-click a link inside a textfield is basically that igonres completely the new LINK event and by default tries to open the link generating an obvious alert message from the browser:
'Firefox doesn't know how to open this address, becuase the protocol (event) isn't associated with any program'.
So far I don't think there is a way to edit or modify this type of context menu.
Sample swf:
Sample Code:- package
- {
- import flash.display.Sprite;
- import flash.events.TextEvent;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- [SWF(width="450", height="150", frameRate="31", backgroundColor="#FFFFFF")]
- public class TextEventLinkTest extends Sprite
- {
- private var myTextField : TextField;
- public function TextEventLinkTest():void
- {
- myTextField = new TextField();
- myTextField.autoSize = TextFieldAutoSize.LEFT;
- myTextField.multiline = true;
- var format:TextFormat = new TextFormat();
- format.font = "Verdana";
- format.color = 0xFF0000;
- format.size = 11;
- myTextField.defaultTextFormat = format;
- myTextField.x=20;
- myTextField.y=20;
- addChild(myTextField);
- myTextField.htmlText = 'With the new method of event handling in AS3,<br>' +
- 'event (asfunction) no longer calls a method you defined but,<br>' +
- 'rather, sends out a TextEvent (<b><u><a href="event:flash.events.TextEvent">flash.events.TextEvent</a></u></b>) of the<br>' +
- 'type <b><u><a href="event: TextEvent.LINK">TextEvent.LINK</a></u></b> for the text field instance in which it exists.<br>' +
- '<br>The text following the event: keyword in the link is accessible from<br>' +
- 'the TextEvent object through its text property.';
- myTextField.addEventListener(TextEvent.LINK, linkEvent);
- }
- private function linkEvent(event_:TextEvent):void
- {
- trace('click: '+event_.text);
- }
- }
- }


