sprite_manager

  parent script for a sprite manager
sprite manager




  sprite manager
The suggestions given by others will definitely do the trick. 
However, I would use a completely different approach if I were going 
to write something like this.

I would choose a range of "empty" sprites to manage and write a 
sprite manager.  You may have similar functionality already.  In 
these "empty" sprites, I would put a zero pixel castmember and attach 
the proper behavior(s).  See my article on DOUG at:

   http://www.director-online.com/accessArticle2.cfm?id=326

That way, all the functionality is already in place (all the 
behavior(s) are there), but it really doesn't do anything, or show 
anything to the user because the cast members are "empty".  When you 
want to allocate a channel, you call this sprite manager, it gives 
you back a channel, then you set the member to whatever you want.

A simple sprite manager could be done like this  (untested - but the 
right idea):

--SpriteMgr
property plAllocation  -- property which is a list of allocations
property pchLow  -- channel of the first sprite to manage
property pchHigh -- channel of the last sprite to manage
property pnmZeroPixelMember  -- number of the zero pixel cast member

on new me, chLow, chHigh
   pchLow = chLow
   pchHigh = chHigh
   pnmZeroPixelMember = the number of member "Hide"  -- a zero pixel 
castmember in your cast
   mInit(me)
   return me
end


on mInit me
   plAllocation = [:]
   repeat with ch = pchLow to pchHigh
     addAProp(plAllocation, ch, FALSE)  -- initialize them all to false
   end repeat
end

on mAllocateChannel me
   -- find the first empty channel
   repeat with ch = chLow to chHigh
     fThisStatus = getAProp(plAllocation, ch)
     if not(fThisStatus) then -- found it!
        setAProp(plAllocation, ch, TRUE)  -- mark it as allocated
        return ch
     end if
    end repeat
    alert("Attempting to allocate a channel, but there are none left")
end

on mDeallocateChannel me, whatChannel
   fThisStatus = getAProp(plAllocation, whatChannel)
   if  not(fThisStatus) then
     alert("Trying to deallocate" && whatChannel && "but it has not 
been allocated")
     return
   end if

   setAProp(plAllocation, whatChannel, FALSE)  -- set the allocation 
back to false
   sprite(whatChannel).member = pnmZeroPixelMember -- reset the graphic
end

Hope this helps,

Irv
-- 
Lingo / Director / Shockwave development for all occasions

Home shock + cgi Bits 'n pieces Director Lingo ShockLets Contact