Articles Archive
Articles Search
Director Wiki
 

Zipping up

May 4, 1998
by Pat McClellan

Dear Multimedia Handyman,

I have built a coat zipper - as in the things you wear, and I want to be able to script a way of doing up & undoing the coat. If you have any ideas they would be greatly appriciated.

Richard Schatzberger


Dear Richard,

Here's the way I would approach it. Create all of your images of the zipper in the various stages of zipped-ness. Let's say that you end up with 15 images. Put them into your cast as consecutive members. Now, create a separate image of the zipper pull-tab.

In your score, let's say you put the zipper image (background) into sprite 4 and the zipper pull-tab in sprite 5. Our goal will be to let the motion of sprite 5 determine which image is displayed in sprite 4.

I'll assume you're using Director 6, so we'll attach a behavior to sprite 5 (the pull-tab). The behavior will allow the pull-tab to move up and down with the mouse, within the limits of your zipper travel distance. For this example, it will travel from a locV of 68 to a locV of 268. As it travels vertically, the number of pixels it travels must be correlated to the number of images you have in the sequence. Our formula will be deltaV * number of images/total range of travel.


property pStartLocV, pStartBG

on beginSprite me
  set pStartLocV = the locV of sprite 5
  set pStartBG = the memberNum of sprite 4
end

on mouseDown me
  repeat while the stillDown
    if the mouseV > 68 and the mouseV ¬
          < 268 then   
      set the locV of sprite 5 = the mouseV
      set deltaV = pStartLocV - the mouseV
      set the memberNum of sprite 4 = pStartBG ¬
            + (deltaV * 15/200)
      updateStage
    end if
  end repeat
end

When you understand what's going on here, there are some improvements you can make to the code. For example, instead of hard-coding the range and number of images, you could create properties for those values which are set in the getProperties description dialog box.

Good luck with your project.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.