Dynamic assigning behaviors

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
theoGA61d2
Posts: 7
Joined: Wed Dec 21, 2011 10:42 am

Dynamic assigning behaviors

Post 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
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Dynamic assigning behaviors

Post 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
Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Dynamic assigning behaviors

Post 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
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Dynamic assigning behaviors

Post by Mark »

Hi,

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

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
theoGA61d2
Posts: 7
Joined: Wed Dec 21, 2011 10:42 am

Re: Dynamic assigning behaviors

Post by theoGA61d2 »

Thanks all, I had found it and it works
Post Reply