Ask a Question related to Macromedia Director Lingo, Design and Development.
-
Listat webforumsuser@macromedia.com #1
How can I attach behaviors to a sprite using another behavior
Hello, Í want to make a behavior to attach other behavior to a sprite, but I don't know how to do it.
Could you help me?
Thanks.
Listat webforumsuser@macromedia.com Guest
-
Flash Sprite loses Cursor Behavior
Hi all, I've been having issues with a Flash sprite in a Director project I'm working on. I'm using Director MX and the SWF is built using Flash... -
attach behavior via lingo not drag and drop?
Hello, Is there a way to attach behaviors to sprites dynamically as the movie plays? I'm trying to create a database driven application that adds... -
Two behaviors with on mouseDown on a sprite
Is it possible to have on the same sprite two diferente behaviors with the sama handler (e.g on mouseDown me ou on mouseEnter me), and have them... -
Sprite behavior on leave
Hi everybody, Problem is like this: I have got two sprites - concentric circles, one big circe placed on bottom layer and smaller one placed... -
Change the cast member of a sprite in a behavior
Greetings all. I'm attempting to publish a director movie(DirectorMX WinXP) that I designed for a video project to the web. The project became... -
JB #2
Re: How can I attach behaviors to a sprite using another behavior
Look into the scriptlist and scriptinstancelist properties of sprites,
Ive done it before but it's a hazy memory now.
JB Guest
-
Robert Tweed #3
Re: How can I attach behaviors to a sprite using another behavior
"Listat" <webforumsuser@macromedia.com> wrote in message
news:bqj7e3$mm5$1@forums.macromedia.com...What a coincidence! I've just written a new function to take care of>
> Hello, Í want to make a behavior to attach other behavior to a sprite, but
> I don't know how to do it.
precisely this job. It emulates the job normally performed by the score, so
you don't need to worry about whether your behaviours will work properly or
not. A tutorial will be coming soon, but using the function is very easy to
use, simply call:
addScriptToSprite( sp, scriptName )
Where sp is either a sprite object or a channel number. The third parameter
is optional, and lets you override the getPropertyDescriptionList defaults
for the behaviour. For instance, if you want to set pProp to something other
than the default specified by getPDL, you would do this:
addScriptToSprite( sp, scriptName, [ #pProp:"use this value" ] )
Heres the code you need:
-- MOVIE SCRIPT: Add a behaviour at runtime.
on addScriptToSprite aSprite, aScriptName, aOverridePDL
-- Make sure we are dealing with a sprite
if( ilk( aSprite, #integer ) ) then
aSprite = sprite( aSprite )
else if( not ilk( aSprite, #sprite ) ) then
return
end if
-- Create the script instance
vScript = script( aScriptName ).rawNew()
-- Add spriteNum and call new()
vScript.setaProp( #spriteNum, aSprite.spriteNum )
call( #new, [vScript] )
-- Get defaults from PDL, if applicable
if( vScript.handler( #getPropertyDescriptionList ) ) then
-- Check PDL override is a list, so we don't get errors
if( not ilk( aOverridePDL, #propList ) )then
aOverridePDL = [:]
end if
-- Get PDL
vPDL = vScript.getPropertyDescriptionList()
-- Get each default from PDL or override list
repeat with i = count( vPDL ) down to 1
vProp = vPDL.getPropAt( i )
if( ilk( vProp, #symbol ) ) then
vValue = aOverridePDL.getaProp( vProp )
if( voidP( vValue ) ) then
vSet = vPDL.getAt( i )
if( ilk( vSet, #propList ) ) then
vValue = vSet.getaProp( #default )
end if
end if
vScript.setaProp( vProp, vValue )
end if
end repeat
end if
-- Add instance to scriptInstanceList
aSprite.scriptInstanceList.add( vScript )
-- Call beginSprite, if applicable
call( #beginSprite, [vScript] )
end
-- END
- Robert
Robert Tweed Guest



Reply With Quote

