2 Replies Latest reply on Oct 28, 2008 12:53 PM by Applied CD

    Adding properties to a sprite?

    Applied CD Level 1
      Is there a way to add a property to a sprite’s existing properties such that it can be accessed with syntax similar to sprite(i).pProperty just like sprite(i).loc or sprite(i).rect?

      I’m trying to use the following behavior to assign a new property pScrollEnable to a bunch of proxy sprites. The behavior itself doesn’t throw an error but testing sprite(i).pScrollEnable throws a property not found error.
        • 1. Adding properties to a sprite?
          James Newton, ACP Level 3
          sprite(1).customProperty will always throw an error if the movie is not running. If you attach your behavior to sprite(1), then run the movie... and then try to access the property that you set in the behavior, it should work fine.

          Having said that, it is generally considered better practice to create an accessor method for the behavior, rather than querying an instance's (supposedly) private properties from outside:

          -- In the behavior
          on IsScrollable(me)
          return me.pScrollEnable
          end

          -- In the Message window
          put sprite(1).IsScrollable() -- may throw a script error if the behavior is missing from sprite(1)

          or

          put sendSprite(1, #isScrollable) -- will fail gracefully
          • 2. Re: Adding properties to a sprite?
            Applied CD Level 1
            Thanks James, I re-wrote it with an accessor method and it seems to work fine.