Articles Archive
Articles Search
Director Wiki
 

A sprite blend behaviour

December 6, 1998
by Pat McClellan

Dear Multimedia Handyman,

I'm trying to write a behavior that when a mouseover occurs on one sprite I want it to change the blend of another sprite, specifically the one in the next channel. I'm able to get the effect to work when I write the script with specific sprite numbers, but I don't know how to write it so I can just drop it on any sprite and it will work from the library. If you in any way could help me with this script it would be appriciated.

Scott Isaacson

Scott,

Good question! I always prefer to avoid making code too specific. Let's figure out what you need. We'll start by assuming that your behavior will default to making changes to the sprite + 1. That will make the coding easy.

We'll create a property to hold the value of the sprite to be affected. I'll call this pBlendSprite, and we'll assign its value in a beginSprite handler.


property pBlendSprite 
on beginSprite me
        set mySprite = the spriteNum of me
        set pBlendSprite = mySprite + 1
end
on mouseEnter
        set the blend of sprite pBlendSprite ¬
          to whatever
end

Easy, right? Now, let's go one step further in your behavior-writing education. Let's make it so that it defaults to be the next sprite, BUT, it can be changed by the author.

This is a bit trickier. In the behavior above, we don't have to know the sprite number until the movie is playing and the beginSprite event happens. But, if we want the default number to show up in the getPropertiesDescriptionList dialog box, we'll need to nab that number immediately -- at the point where the author drops the behavior on the sprite.

The key here is to use "the currentSpriteNum". Read the details in the Lingo dictionary. This property returns whichever spriteNum was most recently involved in an event. Apparently, dropping a behavior on a sprite constitutes an event. That's good for us, because we need to grab that spriteNum value (and then add 1.)


property pBlendSprite
on getPropertyDescriptionList
  set blendSpriteNum = the currentSpriteNum + 1
  set p_list = [#pBlendSprite: [ #comment: ¬
    "Which Sprite blends?:", #format:#integer, ¬
        #default:  blendSpriteNum]]
  return p_list
end
on mouseEnter me
  set the blend of sprite pBlendSprite ¬
    to whatever
end
on mouseLeave me
        set the blend of sprite pBlendSprite to 100
end

Note that in this behavior, there's no beginSprite handler needed. That property gets assigned before the movie even starts playing.

Of course, now that you know how to do this, you'll be able to grab the member of the currentSpriteNum, add 1, and have that cast member show up as a default for other properties. This is done frequently for things like the toggle state of rollOvers.

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.