Page 1 of 1

Dynamic assigning behaviors

Posted: Thu Nov 08, 2012 2:40 pm
by theoGA61d2
Hi I am trying to assign a behavior to a dynamic created graphic but get the following error:
execution error at line n/a (parentScript: bad object) near "graphic id 1109 of card id 1002 of stack "codelibrary" of stack "/Users/theovanstratum/Documents/ProjectX/workflow test.livecode""

The code that assigned the behavior is this:

case "Task"
add 1 to lTaskCounter
put "Task" & lTaskCounter into gName
create graphic gName
set the opaque of graphic gName to true
set the backgroundColor of graphic gName to "white"
set the width of graphic gName to 100
set the height of graphic gName to 50
set the showName of graphic gName to true
set the location of graphic gName to the mouseLoc
set the behavior of graphic gName to the long id graphic id 1109 of card id 1002 of stack "codelibrary"
break

and is part of a popup menu.

The graphic on the card in the substack "codelibrary" exists and the code in there work if I access it on the substack.

Any ideas what I do wrong?

Thanks

Re: Dynamic assigning behaviors

Posted: Thu Nov 08, 2012 2:50 pm
by Klaus
Hi theo,

only BUTTONS can "hold" a behaviour!
Every other objects "just" has a script, but you cannot assign a script to another object
due to some runtime restrictions (check "script" in the docs).

So put the script of your "graphic id 1002 of card id 1002 of stack "codelibrary"" into a button
and THEN you can assign a behaviour to new objects.

Hint you also should add OF:
...
set the behavior of graphic gName to the long id OF graphic id 1002 of card id 1002 of stack "codelibrary"
...

Best

Klaus

Re: Dynamic assigning behaviors

Posted: Thu Nov 08, 2012 2:50 pm
by Dixie
Hi..

Set your behavior to a button, you have to use a button to hold the behavior.. as in ( from the example in the dictionary).

Code: Select all

set the behavior of tNewGroup to the long id of button "Widget" of card "Behaviors"
be well

Dixie

Re: Dynamic assigning behaviors

Posted: Thu Nov 08, 2012 2:52 pm
by Mark
Hi,

Behaviors can only be set to the long id of a button, not a graphic.

Kind regards,

Mark

Re: Dynamic assigning behaviors

Posted: Thu Nov 08, 2012 3:02 pm
by theoGA61d2
Thanks all, I had found it and it works