Set the Behavior Not Working

Roger Guay irog at mac.com
Mon Aug 31 18:01:51 EDT 2015


I think I understand your point here, Richard, except the association with your last sentence. I thought the long id would insure the use of a behavior of buttons outside the host stack. Put here is the thing:

I successfully used this:

	"set the behavior of last image to the long id of button  “myCoolBehavior" of card  “Main””   

 (card “main” is in myCoolSameStack stack)

When I use the message box for the behavior of that image, I get:
	
	"button id 1721 of stack “myCoolSameStack””

why then can I not script:

 	“set the behavior of the image to button id 1721 of stack “myCoolSameStack"?


Thanks, 

Roger





> On Aug 31, 2015, at 12:49 PM, Richard Gaskin <ambassador at fourthworld.com> wrote:
> 
> 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.
> 
> -- 




More information about the use-livecode mailing list