Reassigning stack names in behavior references

dunbarx at aol.com dunbarx at aol.com
Thu Sep 11 16:14:41 EDT 2014


Jim.


Just the sort of cool sort of tools that make LC so much fun. But you need to be careful in the case where controls may have behavior pathNames that call out to more than one stack. You need to make sure that the behavior does indeed reference the deleted ("oldStackName") before it replaces with the new one.


Craig



-----Original Message-----
From: Jim Lambert <jiml at netrin.com>
To: use-livecode <use-livecode at lists.runrev.com>
Sent: Thu, Sep 11, 2014 1:53 pm
Subject: Reassigning stack names in behavior references


Behaviors are very useful. Scott Rossi gave an excellent presentation on them at 
the recent conference.

One thing that sometimes trips me up - I’ll assign a behavior to a bunch of 
controls then I’ll re-name the stack that contains the original behavior button. 

Dumb :( because the controls can’t find the original reference button.

If you ever find yourself in that situation, here’s a script to rename the 
referenced stack names in one shot.

on updateBehaviorStackNames oldStackName
   -- If you change the name of the stack that owns a behavior button, then all 
controls that have that behavior would fail to invoke it.
   -- Use this handler to change the referenced stack in card controls that have 
behaviors.
   -- It will replace the old stackname reference with the new stackname
   
   if oldStackName is empty  then
      beep
      answer error "Please pass old stack name."
   end if
   repeat with x = 1 to the number of controls
      set the cursor to busy
      put the behavior of control x into cBehavior
      if cBehavior is empty then next repeat
      replace oldStackName with the short name of this stack in cBehavior
      set the behavior of control x to cBehavior
   end repeat
end updateBehaviorStackNames

Jim Lambert
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 



More information about the use-livecode mailing list