I've added a boolean - to save a few function calls - and also using a Timer ( instead of an enterframe) on a slowish delay - to save a few processor cycles.
private var tooltipFlag : Boolean = false; /** * @method * @tooltip * @param * @return */ private function detectMouseOverLink( e : TimerEvent = null ) : void { var index : Number = label.getCharIndexAtPoint (label.mouseX, label.mouseY); var url : String = ""; if (index > 0) { var fmt:TextFormat = label.getTextFormat (index, index + 1); if (fmt.url) url = fmt.url; } if ( ( url.length > 0 ) && ( ! tooltipFlag ) ) { tooltipFlag = true; trace('show - url: ' + url + ' tooltipFlag: ' + tooltipFlag ); } else if ( url.length == 0 && tooltipFlag ) { tooltipFlag = false; trace('hide - url: ' + url + ' tooltipFlag: ' + tooltipFlag ); } } If i get time - i might turn this into a utility class - so you can do something like: txtRollOverManger.addRollOverListener( txt , callback ) - or txtRollOverManger.removeRollOverListener( txt , callback ) i have a few textfields - quite a few timers might affect performance... thanks... - karim On 15 Jun 2010, at 14:33, Ktu wrote: > Regardless of whether you are using multiple TextFormat objects or htmlText, > using getTextFormat(begin, end), the textFormat will have the appropriate > url. > This is a quick dirty test. Glad I could help out. I'm posting the code for > my test in case anyone else finds it useful. > > One thing to note! > If text in a textfield does not fill the text field, a error can appear. In > my code below you can see that error. A link on the bottom line will > register when the cursor is in empty space below the link, but not directly > over it. The x property of the mouse is triggering the rollover. Maybe > someone else can explain this issue better. > > > AS3 - Timeline code > > var txt:TextField = new TextField (); > txt.width = txt.height = 150; > txt.multiline = true; > txt.wordWrap = true; > txt.htmlText = "when registered, all <a href=\"www.google.com\">links</a> in > text fields will update <a href=\"www.theflashblog.com\">the status bar.</a> > hahahahah" > txt.border = true; > txt.x = txt.y = 100; > addChild(txt); > > addEventListener (Event.ENTER_FRAME, captureEnterFrame) > > function captureEnterFrame (e:Event):void { > var index = txt.getCharIndexAtPoint (txt.mouseX, txt.mouseY); > var url = ""; > if (index >= 0) { > var fmt:TextFormat = txt.getTextFormat (index, index + 1); > if (fmt.url) url = fmt.url; > } > if (url) { > displayTooltip(url, new Point (mouseX, mouseY)); > } else { > removeTooltip(); > } > } > > function displayTooltip(url:String, pos:Point):void { > if (getChildByName("ToolTip")) return; > var tf:TextField = new TextField (); > tf.name = "ToolTip"; > tf.autoSize = "left"; > tf.text = url; > tf.background = true; tf.border = true; > tf.backgroundColor = 0x00AAAAFF; > tf.x = pos.x + 5; > tf.y = pos.y + 15; > addChild(tf); > > } > function removeTooltip ():void { > var t:TextField = getChildByName("ToolTip") as TextField; > if (t) removeChild(t); > } > > On Tue, Jun 15, 2010 at 9:06 AM, Karim Beyrouti <ka...@kurst.co.uk> wrote: > >> The HREF link is only part the the textfields content, and each textfield >> can have more than one link amongst other copy >> and need to show relevant tooltip only when user is hovering over the 'a >> HREF' parts of the html textfield. >> >> On 15 Jun 2010, at 13:49, Glen Pike wrote: >> >>> Why not use the mouse coordinates? >>> >>> On 15/06/2010 13:24, Karim Beyrouti wrote: >>>> Hi All - >>>> >>>> Wondering if there are any hacks to trigger a 'RollOver' script when >> hovering over a 'a href' link in an html textfield. >>>> Currently using TextEvent.LINK,to trigger links - but would like to show >> a tooltip on rollover (of that part of text). >>>> >>>> So far the only solution i can think of is using : >> TextField.getCharIndexAtPoint(x:Number, y:Number) >>>> create this - but it seems like this could be quite long winded >> solution. >>>> >>>> Any other ways of achieving this? >>>> >>>> >>>> Thanks >>>> >>>> >>>> >>>> Karim _______________________________________________ >>>> Flashcoders mailing list >>>> Flashcoders@chattyfig.figleaf.com >>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >>>> >>>> >>>> >>> >>> _______________________________________________ >>> Flashcoders mailing list >>> Flashcoders@chattyfig.figleaf.com >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders