This content has been marked as final. Show 4 replies
you do want to use sendAllSprites() rather than send sprite. Here's how, and a little explanation as to why:
1. create a behavior script that can be attached to many sprites. Go to the Behavior Inspector tab, click on the "+" and select 'New Behavior' then give it a name such as 'change colour' and click 'ok'. Select it in the cast and click the little script icon at the right of the cast window and then add the code below:
-- behavior script
on changeMyColor me, newColor
sprite(me.spriteNum).foreColor = newColor
2. Select one of the filled shape tools from the Tools bar and draw one on the stage. It will also appear in the score and in a castlib slot as a member.
3. Drag and drop the new shape cast member onto the stage two or three more times. You should have 3-4 filled shapes on the stage.
4. Attach the behavior, 'change colour' onto each sprite on the stage by dragging the script from the cast and onto the sprite then releasing it.
5. Make sure you have the loop playback enabled (from the menu: Control --> Loop Playback should be checked, if not then click it or press Ctrl+Alt+L) and then click on the play button to run the project.
6. To test easily, go to the message window and in the top pane where you can type, type the code below and then hit ENTER:
your sprites should now be a magenta colour. We're using the palette colours from 0-255 on the shape sprites in this example because that's what works for their .foreColor property. This should give you the basics to understand the concepts behind how you can use the sendAllSprites() method. Using sendSprite() will work similarly, but online on one specified sprite. If you want to know where you need to place the sendAllSprites() method in your code then a reminder that Director is an event driven language and that handlers (on mouseUp, on enterFrame, etc.) can be considered it's way of determining a specific event.
repeat with s in spriteList
"FotoArt" <FotoArt@theMaldives.com> wrote in message
> hello everyone
> I have a list of sprites to which I want send a message.
> Is this possible via sendsprite command. I dont want to use send all.
> any guidance will be appreciated.
Originally posted by: Newsgroup User
repeat with s in spriteList
The code above will work as well, however it requires keeping a hard coded list of the sprites or sprite numbers to which you want to send the call. The largest downfall to it is that you must then make sure that list is always accurate. For instance, if you decide, let's say at a later point in development, to move a sprite from channel 4 in the score to channel 20 and that's one of the sprites in the list then you're going to have to remember to change it in your spriteList. By using the sendAllSprites() method you do not have to worry about this issue at all... and how much of an issue is it?... I used to use code such as above and have experienced these extensibility issues which have caused no end of problems in managing code that shouldn't need to be managed.
I try to read the actual posting in my responses. The poster said "I have a
list of sprites".
(this list does not have to be hard coded, in a game, they could be
They also said "I don't want to use send all".
So I answered the question given the poster's criteria.