How can I attach behaviors to a sprite using another behavior

Ask a Question related to Macromedia Director Lingo, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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...
    >
    > Hello, Í want to make a behavior to attach other behavior to a sprite, but
    > I don't know how to do it.
    What a coincidence! I've just written a new function to take care of
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139