Skip to main content
August 18, 2010
Question

Link & RollOver Question

  • August 18, 2010
  • 1 reply
  • 479 views

Hi,

I am creating and formatting text in a text flow in AS3.

I am using Flash Builder 4.

I can not seem to figure out how to:

1) Add a rollover event handler to a link.

editManager.selectRange(start, start+entLength); // use the editManager to select some text in a textFlow

editManager.applyLeafFormat(cf);

editManager.applyLink(ent.URI);

How to I add the event handles that are equivalent to ...

<s:p>Text that includes a link to <s:a href="http://adobe.com/" target="_blank"
                    rollOver="rollOverHandler(event);" rollOut="rollOutHandler(event);">Adobe</s:a>.</s:p>

2) After I accomplish all of this, how do I set the RichTextEditor to that it is not editable?

I want the rollover links to show and for it not to be editable.

Thank you,

Greg

This topic has been closed for replies.

1 reply

August 20, 2010

You need to find the LinkElement and add event listeners to it. This sample works for a simple case where the first character of a link is not nested inside a paragraph or div. If your markup is more complicated you may need to go farther up the parent chain to find the LinkElement.

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"                   xmlns:s="library://ns.adobe.com/flex/spark"                   xmlns:mx="library://ns.adobe.com/flex/mx"                   creationComplete="cc()">      <fx:Script>           <![CDATA[                import flashx.textLayout.events.FlowElementMouseEvent;                import flashx.textLayout.elements.LinkElement;                import flashx.textLayout.elements.FlowLeafElement;                import flashx.textLayout.edit.EditManager;                                public function cc():void                {                     var editMan:EditManager = EditManager(ret.textFlow.interactionManager);                     editMan.selectRange(10,14);                     editMan.applyLink("http://adobe.com");                     var linkSpan:FlowLeafElement = ret.textFlow.findLeaf(10);                     var linkElement:LinkElement = LinkElement(linkSpan.parent);                     linkElement.addEventListener(FlowElementMouseEvent.ROLL_OVER, rollOverHandler);                     ret.editable = false;                     ret.selectable = false;                }                                public function rollOverHandler(evt:Event):void                {                }           ]]>      </fx:Script>            <s:RichEditableText id="ret" text="This is a link test"/> </s:Application>

August 20, 2010

Ah, and I'm not an expert on RichEditableTest, but it appears to me that you need to set both editable and selectable to false to make it work as static text.