Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************************************
- * This function makes it easy to attach a behavior to an object dynamically and
- * also provides an easy reference to that behavior so that the values can
- * also be tweaked dynamically.
- *
- * %obj: The object to attach the behavior to.
- * %behavior: The behavior name (not friendly) you want attached to %obj
- * %behaviorRef: This gets saved as %obj.%behaviorRef for easy reference to the
- * behavior.
- *******************************************************************************/
- function attachBehavior(%obj, %behavior, %behaviorRef)
- {
- %template = %behavior.createInstance();
- %obj.addBehavior(%template);
- %template = %obj.getBehavior(%behavior);
- %str = %obj @ "." @ %behaviorRef @ " = " @ %template @ ";";
- eval(%str); // this line says (%obj.%behaviorRef = %template;)
- }
Advertisement
Add Comment
Please, Sign In to add comment