Button Scripting based on Image

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jnmediaGAd195
Posts: 58
Joined: Mon Dec 05, 2011 5:35 pm

Button Scripting based on Image

Post by jnmediaGAd195 » Wed Feb 29, 2012 11:07 pm

I am cloning a button and putting a different image (cat or dog) on it randomly. Based on the image, I want it play a certain audio clip (meow or bark). I tried this but all I get is barking.


on mouseUp
if the icon of me = "cat.jpg" then
play "meow.wav"
else
play "bark.wav"
end if
end mouseUp

Do I have to make different base buttons for the cat and dog? I would prefer to not do that.

Any help is GREATLY appreciated.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Button Scripting based on Image

Post by sturgis » Wed Feb 29, 2012 11:47 pm

"the icon of me" will return the image id not the name of the image. If your images have been imported into the stack so that the name of the cat image is cat.jpg and the dog is dog.jpg then you should be able do do something like the following...

if the short name of image id (the icon of me) = "cat.jpg" then...
-- do stuff
else
-- do other stuff

end if

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Button Scripting based on Image

Post by mwieder » Thu Mar 01, 2012 12:05 am

Depends on where that script lives. The "me" will resolve to the object containing the script. If this is in the script of the button it will work. If the code is in the card or stack script, you'll have to replace "me" with "the target".

Code: Select all

if the short name of image id (icon of the target) = "cat.jpg" then

jnmediaGAd195
Posts: 58
Joined: Mon Dec 05, 2011 5:35 pm

Re: Button Scripting based on Image

Post by jnmediaGAd195 » Thu Mar 01, 2012 12:34 am

It's working now! Thanks so much for your help! I really appreciate it.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Button Scripting based on Image

Post by Klaus » Thu Mar 01, 2012 12:36 pm

Hi jnmediaGAd195,

I highly recommend to work through these stacks, great learning resources!
http://www.runrev.com/developers/lesson ... nferences/

And welcome to the forum! :D

Best

Kkaus

Post Reply