View Full Version : Detect when user rolls over certain text in html field?
slindberg
March 1st, 2008, 11:58 PM
I'd like to do a term/hint rollover kind of functionality. I have text from XML displaying in an HTML-formatted field, but I'm not sure how to flag a particular word for this. When creating a hyperlink in flash HTML fields, you can of course detect a lick of that link, but can you do anything about when a user rolls over it?
If that's not possible, what work-arounds might there be to simulate this effect?
I wonder about drawing an invisible clip over the word to which I can add a rollover listener. Doing this would require I know the coords that define a box around the word in the text field - is that possible?
FlashingDan
March 2nd, 2008, 03:10 AM
As far as I know there is no built in way to do this. This is a first pass at a function to check which word you are over. I have this function get called in the handler for an EnterFrame event. It will either return a blank string or the word the mouse is over.
Hopefully will at least gets you started. If you need more help let me know, but for now, I need to see about getting some sleep :)
var prevIndex:Number = -1;
var prevWordStart:Number = -1;
var theTextField:TextField = test_txt;
function theWordIs():String
{
var theWord:String = "";
var theText:String = test_txt.text;
var index:Number = test_txt.getCharIndexAtPoint(stage.mouseX-theTextField.x, stage.mouseY-theTextField.y);
// don't run the check if the mouse isn't over anything, is in the same location as the last time or is a space.
grand:if (index != -1 && prevIndex != index && theText.charCodeAt(index) != 32)
{
var wordStart:Number = 0;
var wordEnd:Number = theTextField.length;
// Find where the word starts
for (var i = index; i>=-1; i--)
{
if (theText.charCodeAt(i) == 13 || theText.charCodeAt(i) == 32 || i == -1)
{
wordStart = i+1;
// If it's the same word start as last time, stop the search
if (wordStart == prevWordStart)
{
break grand;
}
prevWordStart = wordStart;
break;
}
}
// Find where the word ends
for (i = index; i<theText.length; i++)
{
if (theText.charCodeAt(i) == 13 || theText.charCodeAt(i) == 32)
{
wordEnd = i;
break;
}
}
// Store the word in the theWord variable
for (i = wordStart; i<wordEnd; i++)
{
theWord += theText.charAt(i);
}
}
prevIndex = index;
return theWord;
}
devonair
March 2nd, 2008, 10:32 AM
I wonder about drawing an invisible clip over the word to which I can add a rollover listener. Doing this would require I know the coords that define a box around the word in the text field - is that possible?
Did that back in the Flash 9 alpha.. This may help out: http://www.kirupa.com/forum/showthread.php?t=236621
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.