Page 1 of 1
Setting the behavior of a control from a script
Posted: Mon May 24, 2010 2:12 am
by phaworth
Reorganising things in my app to work more efficiently, I have the need to change the behavior of a large number of controls. I wrote a script to find the controls in question and change their behavior property by issuing the following command.
set the behavior of button "mybutton" of card "myCard" of stack "myStack" to the long id of button "behaviorbutton" of stack "behaviorstack" of stack "parentstack"
I also tried it with without the final "of stack" string.
I get no compilation or run time errors yet when I look at the behavior setting of the controls in question, they have not changed. This is after I save the .rev file.
I have tried every combination of set commands I can think of in the message box, get no error message, yet the behaviors don't change
There are, literally, hundreds of controls I need to change. Any clues as to what I'm doing wrong?
Pete
Re: Setting the behavior of a control from a script
Posted: Mon May 24, 2010 2:53 pm
by dunbarx
Hi,
of stack "behaviorstack" of stack "parentstack" ?
I think you have too many stacks. A stack cannot an object in another stack. Perhaps lose the "parentStack" part. The long ID will be adequate with just the "behaviorStack".
I assume your "behaviorStack" is a substack of the "parentStack", but this is the way files are organized, not stacks.
Craig Newman
Re: Setting the behavior of a control from a script
Posted: Mon May 24, 2010 5:45 pm
by phaworth
Here's an overview of what I'm trying to achieve.
During development of my first Rev application, I developed a library of reusable objects and buttons that are their behaviors. Whenever I needed one of the objects, I would copy it from it's card to wherever I wanted it to be and it's behavior was already set to the appropriate behavior button. Those objects and behavior buttons were in a substack of the application. Now I'm moving on to other applications and want to use that library of objects in them so I pulled the substack out of my application and put it into a separate stack file that also includes some scripts that I load as front scripts at startup.
That means I have two mainstacks in my application, the application itself and my library stack which I hope explains the need for the "parentstack", although maybe I'm just going about this the wrong way. What I'm trying to achieve is a single maintenance point for the my library of objects and behaviors.
One of the many things I tried was to drop the parentstack as you suggested but still the behaviors weren't updated. I guess as much as anything else, I'm confused by the fact that no errors are flagged when doing these set statements either by script or in the message box. If I'm doing something wrong, which obviously I am, I would expect an error or warning of some sort to be raised.
Still trying different ways of doing this and will update this thread if I find a way that works.
Pete
Re: Setting the behavior of a control from a script
Posted: Mon May 24, 2010 7:02 pm
by dunbarx
Hmmm. Perhaps your final destination is in a stack which has not loaded?
I made two buttons on one card, and put a simple mouseUp script (beep 4) into btn 1 (the parent).
I wrote a one liner in the msg box to "set the behavior of button 2 (the child) to the long id of btn 1". Clicking on btn 2 now beeps.
The buttons containing the behavior script can go anywhere, which is one reason they are so powerful. That is why the long id is used to reference them. You must have some breakdown in the pathname to the behavior button. So first can you check in the inspector to see if the behavior was actually set? Try toggling between the long id of the button and empty, checking each time to see if the behavior is updated. It should be.
Then slowly migrate the child button to wherever you finally intend to store it, checking along the way to see if it still performs. If it does, you should be home free.
Re: Setting the behavior of a control from a script
Posted: Mon May 24, 2010 8:04 pm
by phaworth
Thanks. Pretty sure the stack with the behavior objects on it were loaded but I'll double check that again.
I guess perhaps I should re-examine what I'm trying to achieve and hope that people on this board with more experience of distributing applications than I will comment.
Basically, I want to have a .rev file that contains my script library (which I load as front scripts) and the buttons that represent the behavior scripts of my object library. I'd plan to distribute two .rev files with each application, the application .rev file and the library .rev file. I already use the Stacks panel of the isnpector for the mainstack to refer to the code library and also in the standalone application settings.
With that setup, if I find a problem in the behaviors or front scripts, I just need to fix it and send out a new library file. If someone has more than one of my apps installed, then whatever the bug was will be fixed in all of them by installing the one library file. It also means I just have one place to fix front script/behavior problems as opposed to what would happen if I had copies of those things as substacks in each of my applications. I hope that makes at least some sense!
However, I'm now realizing that the long ID of an object includes the path to the .rev file that the object is in which on the face of it makes the above scheme not feasible. In my own development environment, I have at least two and sometimes three different directories where the .rev files might be stored (one for code/test, one for QA, and one for the standalone application). That means that the path to the my library file will be different in each of those directories and the behavior properties won't be pointing to the correct place. I suppose I could do what I'm trying to do right now in some sort of installation script and change the behaviors so they include the correct directory path - if I can ever get the script to work!
I think the theory of what I'm trying to do hangs together but maybe the practicality doesn't.
Pete
Re: Setting the behavior of a control from a script
Posted: Mon May 24, 2010 8:39 pm
by dunbarx
Post this to the mail list. You might get a different crowd looking at the problem.
Craig Newman
Re: Setting the behavior of a control from a script
Posted: Mon May 24, 2010 8:49 pm
by phaworth
Thanks Craig, will do.
Pete