Genevieve Young <[EMAIL PROTECTED]> wrote:
> When I try to attach a script to a sprite, I receive this message:
>
> Some of the behaviors you selected cannot be attached to the sprites you
> created
>
> Continue Cancel
>
> If I chose continue, the script doesn't run. There is an error message. I
> can't even use the debugger.
Hi Genevieve,
Here's a test I did to produce a similar symptom:
1. I created a new movie
2. I selected the filled rectangle shape tool in the Tools Palette and
clicked on the stage to create a shape sprite
3. I opened the behavior Library Palette at the Automatic section
4. I copied the behaviors "Cycle Colors" and "Random Movement and Rotation"
into the Internal cast window
5. I selected both behaviors and dragged them onto the shape sprite on the
stage. A message appeared:
The behaviors cannnot be attached to all of the
sprites you selected
[ Cancel ] [ Continue ]
(The difference in wording and the position of the buttons may be due
to me working with a different version of Director).
6. I clicked Continue. The "Cycle Colors" behavior was attached to the
sprite, the "Random Movement and Rotation" behavior was not.
Here is the explanation for this. Shape sprites cannot be rotated. They
have no "rotation" property. The "Random Movement and Rotation" behavior
alters the rotation property of the sprite it is attached to. Trying to do
this to a shape sprite will result in a Script Error.
Faced with an alert reporting a Script Error, you might be inclined to think
that the behavior had been badly written. This is not the case. To avoid
such confusion, most behaviors contain a handler which prevents them from
being attached to an inappropriate sprite:
on isOKToAttach(me, aSpriteType, aSpriteNumber)
-- code to determine which kind of sprite the behavior is about to be
-- dropped on and to return TRUE if the sprite and behavior are
-- compatible
end isOKToAttach
This handler is activated when you drag the behavior from the Cast window or
the Library Palette over a sprite. If the sprite fulfils the conditions
defined in the isOKToAttach() handler, a black-and-white checkered band will
appear around the sprite and the cursor will change to an arrow to indicate
that you can attach that behavior to the sprite. If the sprite does not
fulful the conditions, the cursor will remain as a closed hand with a "don't
drop" circle on it. Releasing the mouse button over such a sprite will have
no effect.
The isOKToAttach() handler of the "Random Movement and Rotation" behavior
looks like this (slightly edited):
on isOKToAttach (me, aSpriteType, aSpriteNum)
case aSpriteType of
#graphic:
return getPos([#animgif, #bitmap, #field, #flash, #picture, #text,
#vectorShape], sprite(aSpriteNum).member.type) <> 0
#script:
return FALSE
end case
end isOKToAttach
In other words, you can't drop the behavior on a script sprite (the stage or
the script channel of the score), but you can drop it on any sprite with a
member whose type is listed. Sprites with these member types do have a
rotation property, so the behavior will work.
The issue that you raise occurs when:
* you try to drop two or more behaviors on a single sprite
* you try to drop a single behavior on two or more sprites at a time
In these cases, Director may receive conflicting information from the
isOKToAttach() handler: some sprites and some behaviors may be incompatible.
Director warns you of this, and only attaches the compatible behaviors.
To generalize, the built-in behaviors contain two sorts of handlers:
* Author-time handlers, such as isOKToAttach, getPropertyDescriptionList,
getBehaviorTooltip and getBehaviorDescription. Other handlers which are
called exclusively by these author-time handlers will also be used at
author time only.
* Run-time handlers, such as beginSprite, mouseUp, exitFrame... and any
handlers called by these.
The debugger may not work as fully with author-time handlers in some
circumstances as it does with run-time handlers, since the call comes from
the Director authoring engine, and not from the Player.
In this instance, however, there is no reason to use the debugger: no
breakpoint has been set, and no Script error has occurred.
Does this help?
James
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]