Articles Archive
Articles Search
Director Wiki
 

Tracking the Cursor

October 18, 2001
by Will Turnage

Dear Multimedia Handyman,

Could you tell me how to track the cursor using Lingo in Macromedia Director 8? Sorry to bother you, but could you help me?

Kind Regards,
Jane Costello

 

Jane,

If you want to track the cursor using Lingo, then there are several Lingo properties that can give you this information. The three main Lingo terms you should check out first are mouseLoc, mouseMember, and rollover. Each of these terms are system-level properties, which means that you can call them at any time from any script, and the result is independent of any sprite, member, or behavior on the screen or elsewhere in your movie. The result is based solely on what is happening on the screen at that point in time. Here's the specifics on each Lingo term.

the mouseLoc

The mouseLoc simply returns the location of the mouse within your Director movie as a point.

put the mouseLoc
-- point(119, 158)

You can use mouseLoc to find the exact position of the cursor is in your movie, but you can also use it to determine whether or not the cursor is in your movie at all. If either value in the mouseLoc is negative, that means that the cursor isn't over your Stage. If you want to find just one of the values in the mouseLoc, then you can use the mouseH or the mouseV properties, which return each respective part of the mouseLoc (you can also access them as mouseLoc.locH and mouseLoc.locV). For instance, in the example above, you could have also found each value by typing.

put the mouseH
-- 119
put the mouseV
-- 158

the mouseMember

The next Lingo term is mouseMember, which is a property that returns a reference to the specific member that the mouse is currently over.

put the mouseMember
-- (member 22 of castLib 1)

If the mouse isn't currently over any member, or is off the stage, then mouseMember will return VOID so it's important that you don't always assume that mouseMember will return a member as its value.

the rollover

The third Lingo term you should know about is rollover, which is similar to mouseMember. However, instead of returning the member that the cursor is over, it returns the spriteNum of the sprite that the cursor is currently over.

put the rollover
-- 16

If the cursor isn't over any sprite, or is off the stage, then rollover returns 0. Another feature of rollover is that you can also use it as a function to test for whether or not you are rolled over a specific sprite. In that case, rather than calling the rollover, you just use the word rollover followed by the sprite number you want to test. For example,

put rollover (16)
-- 1
put rollover (15)
-- 0

With these three Lingo terms, you can track all sorts of information about where the cursor is on the screen and what it's currently over. But these aren't the only system properties that give you information about the cursor. Once you get more involved with Lingo, you will learn about a few other Lingo terms that help you track the cursor. For instance, when you're working with fields there are four Lingo terms you can use to track where the mouse is within the text of the field member. These terms are mouseChar, mouseWord, mouseItem, and mouseLine.

When the mouse is currently over a field, each one of these system properties returns the number of the character, word, item, or line that the mouse is currently over. This can be very effective when you use it in combination with the other lingo terms mentioned earlier. For instance,

put (the mouseMember).word[the mouseWord]
-- "inside"

In this code, you're finding out the exact word that the cursor is over by finding the index number of the word and looking up that number word within the field member that the cursor is over.

If you're still confused, check out this sample movie which allows you to watch all of these system properties change as you move the cursor around the screen.

 

A sample movie is available for download in Windows or Macintosh format.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.