Friday, February 10, 2006

Flex 2 - MouseWord by Ralf Bokelberg

Ralph created an excellent example for Flex By Example that demonstrates how to retrieve the current word underneath the mouse cursor. This type of functionality is available in Flash Player 8.5 through the use of a new method from the TextField class - getCharIndexAtPoint. Ralph used this method and created a new function that return the word under the mouse cursor. Because this functionality is encapsulated in a new function, so it's easy to transition into your own projects.

This type of functionality can have practical uses in your projects. For example, you can implement "hover" capability for certain words in text fields. When the mouse stops moving for a certain amount of time, examine the word underneath the cursor. If the word has metadata associated with it, you can display the data in a tooltip like fashion. Think of the case where an acronym might have what it stands for appear as a tooltip when the mouse hovers over it.

I can also envision this in a drag and drop style interface. Perhaps a simple game is created that tries to match a word with a definition. By dragging a definition over a word and releasing the mouse, you can examine the word underneath the cursor and decide if the definition matches it or not. Or, instead of definitions, perhaps the user must match synonyms or antonyms instead.

Either way, the example that Ralf provides is simple to grasp and easy to adapt to your own needs. Great job Ralf!


Open Example SWF in a New Window



This example is available with full source and documentation within Flex® by Example.

More to come.

Darron :)

1 Comments:

At May 26, 2008 3:33 PM, Blogger fabrice said...

Finally a msword fn!! Director still have this fn since v3.0!

 

Post a Comment

<< Home