How to safely set the icon of a button ?
Alex Tweedly
alex at tweedly.net
Mon Feb 28 16:24:38 EST 2005
J. Landman Gay wrote:
> Even if you use an image's short name as an icon reference, the engine
> will try to resolve that into an image ID number. Under the hood, only
> ID numbers can be assigned as icons. So I'm guessing your image IDs
> duplicate some of those in the Rev IDE. Since it is possible to assign
> an ID to an image (they are the only controls that allow this, and it
> is for this exact reason) just assign a different ID to the images
> that conflict.
I tested this out by simply changing it in the Inspector - and of course
it worked (thanks again).
But for the real solution, I wanted to reset the image IDs under program
control (so the app can tell my library what values it is allowed to use
to avoid conflicts). I wrote a simple function to do this -
> function PlCardInitialize pStartID
> local tID
> put pStartID into tID
> if tID is empty then put 234000 into tID -- memorable number in
> "reserved for app" range
> repeat with i = 1 to the number of controls in stack "Playing Cards"
> if word 1 of the name of control i of stack "Playing Cards" =
> "image" then
> add 1 to tID
> set the ID of control i of stack "Playing Cards" to tID
> end if
> end repeat
> return tID+1
> end PlCardInitialize
>
and called this from the "openstack" of my app. This worked (I'm sure)
when I first tried it ..... but when I close down and re-opened the
stack, I get an error
executing at 9:13:45 PM
Type Image: image must be open to set id
Object Playing Cards
Line set the ID of control i of stack "Playing Cards" to tID
Hint 234001
What exactly does "image must be open" mean ?
I tried delaying the call to PlCardInitialize until after the image has
been referenced (i.e. specified as the icon for a button), and indeed
until after it has been displayed - and still get the same error.
When I first tried it, I probably had the library stack open - but can't
think of anything that I would have been doing to the images themselves.
--
Alex Tweedly http://www.tweedly.net
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.3 - Release Date: 01/03/2005
More information about the use-livecode
mailing list