Showing/Hiding Images on mouseLeave...
John J. Theobald
mailjjt at bellsouth.net
Fri Feb 7 20:24:01 EST 2003
Igor de Oliveira Couto wrote some time ago:
> Dear Revolution Masters,
>
> I'm trying to implement a simple button that should use 3 different
> images: 'idle', 'over' (when the cursor in on top of the button), and
> 'down' (when the mouse is down on the button).
>
> Because the shape of the button is irregular, and I want the
> transparent bits to be ignored for mouse events, rather than specifying
> the images as icons in a button control, I used IMAGES. My idea was to
> setup the 3 images on a card, on top of each other, and simply
> show/hide each one in response to the appropriate mouse events.
>
> So I started by putting the 'idle' image on the card, and then the
> 'over' image on top of that, making sure the 'loc' properties of both
> was exactly the same (ie, they were exactly on top of each other). Each
> picture is exactly the same as the other, just using different
> colours... Now, I went into the scrip of the 'idle' picture, and typed:
>
> on mouseEnter
> show image "over"
> hide me
> end mouseEnter
>
> Then, I went into the script of the 'over' image, and did the opposite:
>
> on mouseLeave
> show image "idle"
> hide me
> end mouseLeave
>
> Now, what is happening when I use the browse tool is a bit of a puzzle:
> it goes like this:
> The card is displaying the 'idle' image. I move the cursor into the
> image, and presto, I see the 'over' image. I also know that the 'idle'
> image HAS been hidden - I can check with the message box...
> Now, I slowly move the cursor OUTSIDE the image, and... nothing. The
> 'over' image behaves as if it has NOT received the 'mouseLeave'
> message...
> I move the cursor back onto the 'over' image, and move it back out -
> now for the second time - and, presto, it works: it hides the 'over'
> image and shows the 'idle' image.
> The crunch of the matter is: I have to 'leave' the image TWICE for it
> to work... EVERYTIME!
>
> All I can deduct is that for some reason, the first time the mouse
> leaves the 'over' image, no 'mouseLeave' message is being sent to it!
> Only after the cursor has re-entered the image, and then proceeds to
> leave again, does it work...
>
> Am I missing something embarrassingly simple? Did I not read the
> documentation properly? Is this a behaviour that others have noticed?
> Is it a bug?
>
> Any help would be greatly appreciated!
>
> Kind Regards,
> --
> Igor de Oliveira Couto
> ----------------------------------
> igor at pixelmedia.com.au
> ----------------------------------
>
Igor,
I ran into this problem on MC 2.4.3 while developing. I searched the
archives and saw your posting along with numerous responses but no clear
solution.
Here is how I solved the problem, for those that may (or may not) be
interested. I chased the problem like many others by trying to get the
button to do what I wanted on the mouseLeave. Then it occured to me, if
I am leaving one object, I must be entering another so...
I simply put a transparent graphic behind my "freeform" shaped button.
This graphic extends beyond the borders of my button. I then put this
handler in the graphic.
on mouseEnter
put image "normalstate" into image "goback"
end mouseEnter
"goback" is the name of my "freeform" button, "normalstate" is the image
I want displayed when I do a mouseLeave. Since leaving the button does
not generate a mouseLeave (as you discovered), entering the transparent
graphic DOES generate a mouseEnter and the opportunity to change the
graphic. You could, of course, reference a file, imagedata (and
maskdata if needed),or just a hidden image as I do. All of which were
recently discussed in another thread.
Sorry if this is old news, but since I did not see a solution posted, I
thought I would pipe up.
Regards,
John Theobald
More information about the use-livecode
mailing list