MovieClip-esque’ Sprite Creation in Director

I missed my attachMovie and removeMovieClip commands from Flash whilst in Director, and after not being satisfied with some of the sprite engines posted on <a href=””></a>, I built my own. It’s far from complete, as I added like no error checking, but it still works as long as you don’t screw up (like attach a sprite to the same depth, but that doesn’t work well in Flash either, now does it?)

Like everything in Director, though, you need at least something on the stage to get this to work. It’s really simple, though.

– open the bitmap window
– give it a name “blank”
– close the bitmap window. This should put it as a cast member in your case
– add it to sprite channel 1
– repeat the same keyframe for as many sprites as you think you’ll use (I did the max, 1000, cause I’m freaky-deaky like that)
– add this code as a movie script (or with your other code)
global gSprites

on prepareMovie

gSprites = [:]


on attachSprite memberName, spriteName, spriteDepth
s = Symbol(spriteName)
if voidP(gSprites[s]) then
sprite(spriteDepth).member = member(memberName)
sprite(spriteDepth).member.regPoint = point(0, 0)
gSprites[s] = sprite(spriteDepth)
return sprite(spriteDepth)
end if

on removeSprite spriteName
i = gSprites.getOne(spriteName)
if voidP(i) = false then
s = Symbol(spriteName)
gSprites[s].member = member(“blank”)
gSprites[s].locH = 0
gSprites[s].locV = 0
return true
return false
end if

on gSprite spriteName
return gSprites[Symbol(spriteName)]

Now, if you want to use it, just do:
— attach
mySprite = attachSprite(“MemberName”, “spriteString”, 1)
mySprite.locH = 320
mySprite.locV = 240
— remove

And, instead of that sprite(5) bs, you can do:
gSprites[#spriteString].locH = 5
–or, if your not familiar with Symbols in Director
gSprites[Symbol(“spriteString”)].locH = 5
— or
gSprite(“spriteString”).locH = 5

:: extends chin ::
Tasty beef!

4 Replies to “MovieClip-esque’ Sprite Creation in Director”

  1. This is great, Jesse!

    But you forgot one more syntax option – my personal favorite – complete dot notation:

    gSprite.spriteName.locH = 5

Comments are closed.