6b: Handle
The "Drag Element b" parent script
What it does
This works in conjunction with the "Drag
Element" behavior. If you use the "Drag Element"
behavior, you need to also drop a copy of the "Drag Element b"
parent script in a cast. If you use the "Drag Element" behavior
without dropping the "Drag Element b" script in a cast, WFS
will remind you about it.
Deeper: What it does
The "Drag Element" and "Drag Element b" scripts
are edited versions of the "6: Handle"
and "6b: Handle" scripts which allow
you to drag a multi-sprite around, not just an element.
In WFS 3.0, each "6: Handle" behavior
had an 'enterFrame' handler. WFS now eliminates this handler from
the
"6: Handle" behavior. Instead, on mousedown, the "6:
Handle" behavior notifies a "6b: Handle" child object
(named gWFSHandle, a global variable) that it is active. The "6b:
Handle" child object has a stepFrame handler. The stepFrame
handler processes active handles.
This means you can attach as many "6: Handle" behaviors to
different sprites as you like, and it doesn't degrade performance, ie,
however many "6: Handle" behaviors you use, only one stepFrame
handler per frame is executed, and when it executes, it deals with only
instances of "6: Handle" that are active in dragging a multi-sprite
around.
The "Drag Element" behavior and "Drag Element b"
script are identical to the above scripts except you're dragging an
element, not a multi-sprite. So the "Drag Element b" script
is there to get rid of the need for a frame event handler in every instance
of the "Drag Element" behavior.
These stepFrame handlers in "Drag Element b" and "6b:
Handle" are the only frame event handlers in WFS, ie, WFS does
very very little background computation. You can attach as many instances
of the "Drag Element" and "6: Handle" behaviors
to as many sprites as you like without worries of eating up CPU cycles
needlessly.
"Drag Element b" child object creation is automatic
If you look in the prepareMovie handler in the "1: prepareMovie"
movie script, you see the below code:
if wfsMemberExists(member("Drag Element b")) then
gWFSDragElement=new(script "Drag
Element b")
add the actorList,
gWFSDragElement
end if
In other words, if some cast contains the "Drag Element b"
script, the prepareMovie handler creates gWFSDragElement (a global)
and adds it to the actorList so it receives stepFrame messenges. You
don't need to add any lines of code to make it work.
If the "Drag Element b" script is not present and you do
use the "Drag Element" behavior, WFS reminds you to drop
the
"Drag Element b" script in a cast. This is done with code
in the beginSprite handler of the "Drag Element" behavior.
|