Page 1 of 1

Calling a command on button press

Posted: Mon Dec 20, 2010 1:04 pm
by seamus_waldron
Here's the problem.

I have 10 buttons. Each button does the same thing, except for one small variation. Obviously, it makes sense to use a command to do the processing and pass in any parameters.

So, for the button "buttonNumber1", the code looks like this:

on mouseDown
displayNumber 1
end mouseDown

In my card code, I have :

command displayNumber thisNumber
local baseIcon = 7097

local thisButton

put "buttonNumber" & thisNumber into thisButton
set the icon of button thisButton to baseIcon + 10 + thisNumber

play specialFolderPath("engine") &"/assets/audio/number" & thisNumber & ".m4a"

wait 1.5 seconds
set the icon of button thisButton to 0
end displayNumber

It doesn't really matter what the command is doing, but just for completeness, it create sand puts the name of the button into the variable thisButton and sets the icon of the button to an image. It then plays an audio file (stored in /assests/audio), waits for the sound to complete and resets the icon of the button to nothing.

Running within LiveCode, this works fine.

Running in the simulator and on a real device, nothing happens.

The command displayNumber and the button are in the same card.

In an experiment to see if there is a scope problem, I put the definition on the command at the button level scope and everything worked fine.

Any help would be appreciated as the only alternative I will have is to duplicate the same code for every button which will just grate on my nerves :-)

Re: Calling a command on button press

Posted: Mon Dec 20, 2010 2:52 pm
by bn
Hi seamus,

I took your script and made a little stack that replicates the folder structure and everything else you scripted. It works for me in the simulator (cant connect my iPhone since I forgot my cable today). The only thing I noticed was that when I converted an aif file to an iPhone file the suffix provided by Quicktime Player 7.x.x was m4v and not m4a as in your script. Maybe m4a does not play on an iPhone? Just a guess since everything else was exactly as in your script.
this worked in Livecode 4.5.2 and later.
regards

Bernd

Re: Calling a command on button press

Posted: Wed Dec 22, 2010 11:27 pm
by seamus_waldron
Bernd,

Thanks for the reply, it confirmed that the problem must be with me, and sure enough, it was.

I have everything running fine now with the command defined in the script of the stack.

Seamus