mouse entered handler

i have a transparent button with the mouse entered handler. what i’m trying to do is have the background image change when the mouse is over the transparent button. but the mouse entered handler doesnt seem to work, i tried putting a display dialog in it to test if it worked and nothing happens when i put my mouse over the button.

Just out of curiousity, did you remember to select the checkbox in Interface builder that links the button with the handler in your applescript?

yes, i did.

I used the suggestion from SwissalpS supplied in the link below, I changed it to be “on awake from nib theObject” instead of “on launched theObject”, just need to define your bounds, worked pretty well.

http://bbs.applescript.net/viewtopic.php?id=19306

what are bounds? and i put this in the awake from nib handler for my window?

bounds are in this case the bounds of window “main” it’s size and position, their may better ways to do this
have a search around

ok in the awake from nib handler for the window i put this

on awake from nib theObject
	tell window "main" to set bounds to (bounds of window "main")
end awake from nib

and i get this error:

Can’t make bounds of window “main” of window “main” into type «class qdrt». (-1700)

then this is what happens when the mouse is rolled over a button that i named menu:

NSUnknownKeyScriptError (7)

and this is the code thats there for that button when you rollover it:

on mouse entered theObject event theEvent
	set the_app to path to me as string
	set thePath to the_app & "Contents:Resources:"
	if theObject's name is "menu" then
		set image of image view 1 of window "main" to thePath & "blackpodmenu.psd"
end if

Hi,

As we have no access to your codes and nibs, this is another “out of curiosity” question:
Did you click the “on mouse entered” thingy in the AppleScript pane to connect to your transparent button?

After that, you should also have a “on mouse exited” contrasting handler.

One other thing you may like to check is if your object is in front or at the back. When you click the button, does the AppleScript pane indicate the name of your transparent button? If not, consider clicking your button in the IB and send it to the front in the Layout menu. That way, it’ll respond to the “mouse entered” action assuming you have all things taken cared of.

I have had no problem with this handler so I am just wondering why you’re having difficulty with it.

Good luck.

archseed :slight_smile:

the handler is working, now i’m just having some coding problems. see my post above.

Hi,

I suggest referring to the documentation on image and loading it.

I have a program that does this but I am in the office right now. Will check on that later on and get back to you.

Good luck meanwhile.

archseed :slight_smile:

Hi,

OK, just got back home for quick lunch and opened the image viewing program that I have. Maybe you can pick up a thing or two from this.

Basically, I have a program that sources a folder full of images. Then, I copy every image file of that folder into a list (list_imagefiles). From there, I take a random picture out of the list and have that picture file loaded like this:


set imageFile to item randompic of list_imagefiles
set theFile to (imageFile as string) as file specification
set newImage to load image (theFile)
set image of image view "myPicture" to newImage

The image view “myPicture” is a window with an NSImageview in it to hold the picture or image. I checked if buttons can hold an image and the documentation says it does. So, your problem should easily be resolved by correcting your codes.

Good luck. I hope the above helps.

archseed

thanks, that worked but i still have this problem

Hi,

I never used that code in my program yet mine still worked.

Try deleting that “bound setting” thing and see what happens.

Good luck.

archseed :slight_smile:

This topic has perplexed me, and I have yet to find a single, simple method that will enable the button to respond to the mouse entered and exited events in asstudio. To get the button to respond to either of these handlers, it seems that you have to adjust the size (or bounds) of the window to a value other than that which it is set to when it is first drawn. This appears to somehow update the button’s properties/connections/whatever and allow them to respond to the events. I’d call that a bug. The reason that setting the windows bounds to its current bounds doesn’t work seems to be a bug, also. But, if you get the size as a list, and then set it to that list, it works as expected. What I’ve done is to change one of the size values and then change them back when the window first awakens from nib, so the user never sees this hack in action (see the awake from nib handler below) and get the benefits of the window handling it’s own bounds (such as when using auto save).

As a side note, it is unwise to continually load images every time you display them… especially in the case of a recurring event such as a rollover, where the user could ‘abuse’ the effect by going crazy with the mouse. This is an unnecessary burden on memory, and could lead to unexpected rendering results. You should pre-load the images into persistent variables and set the image to the preloaded one when toggling the image. This can be done in any awake from nib handler, or more approriately, in one of the application’s launch-time handlers such as ‘will finish launching’.

Here’s the code I came up with…

property image0 : null
property image1 : null

on mouse entered theObject event theEvent
	if name of theObject is "button" then
		set image of image view "imageView" of window "window" to image1
	end if
end mouse entered

on mouse exited theObject event theEvent
	if name of theObject is "button" then
		set image of image view "imageView" of window "window" to image0
	end if
end mouse exited

on will finish launching theObject
	set image0 to load image "imageRegular"
	set image1 to load image "imageRollover"
	set image of image view "imageView" of window "window" to image0
	show window "window"
end will finish launching

on awake from nib theObject
	if name of theObject is "window" then
		tell theObject
			set {sH, sV} to size
			set size to {sH + 1, sV} --> Set the size...
			set size to {sH, sV} --> ...now set it back
		end tell
	end if
end awake from nib

i found also that if you use “first responder” that works as well
would not work using a button, or targeting window “main” though

ie:

on awake from nib theObject
	tell window "main"
		set first responder to text field "textfield1"
	end tell
end awake from nib

Oh my god, what a mess!!! :wink:

¢ Never name a variable with a reserved word (bounds)
¢ you use double referencing (tell window. and .of window)
either

tell window "main" to set theBounds to its bounds

or

set theBounds to bounds of window "main"

works

Stefan, he’s not trying to set a variable named ‘bounds’ to the bounds. He’s actually trying to set the windows BOUNDS to it’s own bounds. This technique makes the window redraw itself, which in turn makes the button (for some unknown reason) begin to intercept the mouse events. But for this to work you must CHANGE the bounds from what they currently are… it won’t work to simply set them again to their current value. Check out my previous post for my example of changing the size of the window and then changing it back. Ultimately, the problem is not inherent in getting and then setting the bounds. The problem is with trying to get and set the bounds of the window in one line (i.e. ‘tell theObject to set bounds to bounds’). For some reason this throws an error. There is probably a command such as ‘display’ or ‘update’ (although neither of these actually worked) which will make the window redraw without having to do this hack of sizing it and then resizing it back.

fiftyfour123, I agree with stefan about his 2nd point. While redundant references may or may not work, it’s important to get into the habit of writing intelligent code. You may find that a lot of your problems are solved by being a bit more efficient and methodical about how you write your code. I will say that you did a good job taking what was posted on the other page, making relative sense of it, and using it in a logical way. It took me a while to verify there was simply no way to pass the windows bounds back to itself without being more verbose about it. Just spend a bit more time thinking carefully about code you cut and paste into your scripts and you’ll take care of these sorts of things.

j

how come i dont have the on will finish launching handler, is that only in document based apps? i tried using on will open instead and when i rolled my mouse over a button it said the variable (of the image) was not defined, so it must have something to do with the on will open part.

EDIT: i get error -2706 which is coming from the will open handler.

The ‘will finish launching’ handler is connected to the application object (File’s Owner) not the window. I don’t see any reason why it would not work from the will open handler, as that’s the handler I originally used to test this code. Did you incorporate ALL of the elements that I posted in my sample code? All of them are REQUIRED. I rarely post any code that is unnecessary, and I always post what is required of you to perform a given task. Make sure you have the property variables declared at the top of the script. If you did not do this, the references to the images will not be persistent and they will of course have undefined values. Also, move the code into the ‘will finish launching’ handler. Not only is it a more appropriate place to execute this code (keeping the initialization of application-level objects in an application handler), it is unnecessary to keep performing the resizing routine every time the user opens the window. It only needs to happen once, at startup.

Make sure you look over everything people post carefully. It seems like you’re not really paying attention to what’s being offered, and the stuff we’re posting is extremely fundamental. The code I posted is all you need to handle the rollover of a button to make an image view change its image. No more or less. Just try getting this to work… in a separate test project if you need to… and then make changes to suit your unique needs.

j

ok, this is what i have in the will finished launching handler


on will finish launching theObject
	set the_app to path to me as string
	set thePath to the_app & "Contents:Resources:"
	set blackpod to load image thePath & "blackpod.psd"
	set blackpodmenu to load image thePath & "blackpodmenu.psd"
	set blackpodnext to load image thePath & "blackpodnext.psd"
	set blackpodback to load image thePath & "blackpodback.psd"
	set blackpodplay to load image thePath & "blackpodplay.psd"
	set blackpodaction to load image thePath & "blackpodaction.psd"
	set blackpodmenuin to load image thePath & "blackpodmenuin.psd"
	set blackpodnextin to load image thePath & "blackpodnextin.psd"
	set blackpodbackin to load image thePath & "blackpodbackin.psd"
	set blackpodactionin to load image thePath & "blackpodactionin.psd"
	set blackpodplayin to load image thePath & "blackpodplayin.psd"
	set image of image view 1 of window "main" to blackpod
	show window "main"
end will finish launching

and it still says that the variable blackpod is not defined when the app opens.