Set the Behavior Not Working

Richard Gaskin ambassador at fourthworld.com
Mon Aug 31 15:49:31 EDT 2015


Roger Guay wrote:

> Can anyone tell me why this:
>
> 	"set the behavior of image id 1727 to button id 1721 of stack “mySillyStack”"
>
> does not work! i.e. it empties the behavior of image id 1727
>
> Yet, I can paste:
>
> 	"button id 1721 of stack “mySillyStack”"
>
> into the behavior of image id 1727 and it works???

I don't know if this will clarify or confuse, but here goes:

Remember that in LiveCode objects are often containers, allowing us to 
do things like:

   put field 1 into field 2

This works with button contents, and image contents as well - try this 
in the Message Box:

   put image 1

You should see the binary image data in the Message Box, since that's 
the value contained in that control.

Buttons can contain data as well.  When the button is used as a menu 
this data is the list of menu items, but any button can have data stored 
in it - try this on a standard push button:

    put "Something" into btn 1; put btn 1

The "set the behavior" command expects a *reference* to an object, but 
usually can't understand the *contents* of an object.

So it may be helpful to think of your line as:

    set the behavior of image id 1727 to \
      (button id 1721 of stack “mySillyStack”)

...which obtains the text of the button, if any, and then attempts to 
set the image's behavior property to that value.  If we had used the 
button we created in the above example as our object, your script line 
would be interpreted as:

    set the behavior of image id 1727 to "Something"

...which of course can only confuse an otherwise-reasonably-smart 
LiveCode engine.

So as a general rule, having a habit of using the long id of an object 
will give you a reliable *reference* to an object whenever's a reference 
is needed, such as in the behavior property.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list