3 Replies Latest reply on Mar 25, 2008 10:23 PM by stephen_

    Why didn't anyone tell me you could name sprites now?

    Level 7
      Damn, it's about time they added this feature. I can't believe how long it
      took me to notice. Hooray for no more updating all the code every time I
      move the sprites down a channel or coding in cumbersome global property
      lists to keep track of where all my sprites are...


        • 1. Re: Why didn't anyone tell me you could name sprites now?
          Level 7
          Darrel Hoffman wrote:
          > Damn, it's about time they added this feature. I can't believe how long it
          > took me to notice. Hooray for no more updating all the code every time I
          > move the sprites down a channel or coding in cumbersome global property
          > lists to keep track of where all my sprites are...
          >
          >
          I still use 8.5, so no sprite naming. But an easy workaround was to
          create a global variable (gSpriteNames = [:]) and use an onBeginSprite
          handler like:

          property spriteNumber
          global gSpriteNames
          on beginSprite
          gSpriteNames[#someSpriteName] = spriteNum
          end

          and then anywhere I need to, reference the sprite as
          gSpriteNames.someSpriteName

          It's worked out for me in past, and not too big of a pain. Of course the
          new sprite naming would be better.
          • 2. Re: Why didn't anyone tell me you could name sprites now?
            Level 7
            > I still use 8.5, so no sprite naming. But an easy workaround was to create
            > a global variable (gSpriteNames = [:]) and use an onBeginSprite handler
            > like:

            Yeah, that's pretty much what I was doing (that's what I meant by
            "cumbersome global property lists"). The biggest problem I had with that
            was that I didn't know you could do gSpriteNames[#someSpriteName] =
            spriteNum, so I was doing it with
            gSpriteNames.addProp(#someSpriteName,spriteNum), which I discovered was
            creating a memory leak - every time a sprite's beginSprite code ran, it
            would add a duplicate value to that property list, which would ultimately
            get too big and crash the program, and so I had to first check to see that
            it wasn't already on the list before adding itself, etc. Then I had to then
            add code to each sprite to REMOVE itself from said property list on
            endSprite... At any rate, naming sprites is 100x better, so far about the
            only new feature in MX 2004 I can actually USE, but by itself well worth the
            price of upgrading.

            I just can't believe it took so long to implement this feature. I think
            I've been putting in a request for this on their wishlist after every new
            version since Director 5 or so. And when they finally did implement it, it
            seems like it was just quietly slipped in there - I didn't see mention of
            this on any of the "What's New" documents - they spent all their time hyping
            the Javascript support and Flash Components, which I barely touch. By
            contrast, this is something I will be using on probably every project from
            now on. In fact, I think I may load up a couple old projects and change
            them all so they work this way. It just makes so much more sense than the
            old way, and requires no scripts to implement, so it's less likely to screw
            up.


            • 3. Re: Why didn't anyone tell me you could name sprites now?
              stephen_ Level 1
              quote:

              Originally posted by: Newsgroup User
              Yeah, that's pretty much what I was doing (that's what I meant by
              "cumbersome global property lists"). The biggest problem I had with that
              was that I didn't know you could do gSpriteNames[#someSpriteName] =
              spriteNum, so I was doing it with
              gSpriteNames.addProp(#someSpriteName,spriteNum), which I discovered was
              creating a memory leak - every time a sprite's beginSprite code ran, it
              would add a duplicate value to that property list, which would ultimately
              get too big and crash the program, and so I had to first check to see that
              it wasn't already on the list before adding itself, etc. Then I had to then
              add code to each sprite to REMOVE itself from said property list on
              endSprite... At any rate, naming sprites is 100x better, so far about the
              only new feature in MX 2004 I can actually USE, but by itself well worth the
              price of upgrading.



              There's always
              gSpriteNames.setAProp( #someSpriteName, spriteNum )

              I know it's redundant now that you've discovered naming but it saves checking if a prop exists before using addProp.