7 Replies Latest reply on May 27, 2012 6:51 AM by nairkat

    Attatching library behaviors during runtime?


      Well I have a graphic on the screen (not on the score but it's a child object that takes a sprite channel when it's created) but I want it to appear using the "Pixelate" behavior from the library. I want to know if by asigning it to a sprite scriptInstanceList or scriptList (and maybe then running a custom on runPropertyDialog event handler that I would have to create cause it's not present in the original "pixelate" behavior, although I guess that's not big deal doing through a duplicate of the behavior) it could be posible to effectively apply this interesting effect. The other alternative I'm thinking about is copying the parts of the behavior that I want into my scripts and adapt them as needed.

        • 1. Re: Attatching library behaviors during runtime?
          Sean_Wilson Adobe Community Professional

          Try it and see - no reason it wouldn't work if implemented correctly.

          • 2. Re: Attatching library behaviors during runtime?
            nairkat Level 1

            Before creating this post I had tried by adding it to scriptInstanceList right before (the line above) creating the child object of the graphic that must play the effect (and adding the "behavior" parameters list for the behavior), it didnt work, I tried it then adding it after the child object is created and it didnt work either. Tried with scriptList doing the same 2 things and didnt work. So I think the only thing left to try before canibalazing the script (sounds fun ) is try the on runPropertyDialog thingy that is supposed to override the parameters defined by onGetPropertyDescriptionList. Will post results!

            • 3. Re: Attatching library behaviors during runtime?
              Production Monkey Level 3

              You need to write a constructor - a "new" handler - to initialize the properties that are specified in the getPropertyDescriptionList handler. Also set the property SpriteNum. Then after calling new you call beginSprite.  That should make it work.  Forget about the ScriptList stuff. That is for score control.

              1 person found this helpful
              • 4. Re: Attatching library behaviors during runtime?
                nairkat Level 1

                Thank you for the input, will try that for sure! Just to clarify,  if I'm understanding you correctly I need to treat it as a child object for the first part of it (but excluding adding it to the scriptInstanceList since probably it's not suited for the situation as it's not a child object or parent script instance what we are dealing with actually but a behavior instance). Call the new handler created (within a copy of the pixelate behavior I asume) and then call beginSprite of the "pixelate" behavior. Is that what you meant?

                • 5. Re: Attatching library behaviors during runtime?
                  Production Monkey Level 3

                  The differences between Parent, Movie, and Behavior scripts is very minor; Important, but minor.


                  You can call "new" on any type of script and an object instance will be returned. All scripts have an implicit new handler for constructing instances of scripts.


                  When you call "new" on a behavior you are doing the same thing Director does when it encounters a new sprite in the score that has a behavior attached.  Director instantiates an instance and then assigns values to the instance properties that are listed in the scriptList. Since you are instantiating the behavior script through code, it is up to you to initialize the properties.


                  It's important to remember that when an instance of a behavior is added to a sprite's scriptInstanceList, the sprite inherits all the properties and handlers of that instance.


                  What I would do is copy the "Pixelate" code to a new behavior script and make your modifications there. You could also use inheritance via the ancestor property if you would like to up the challenge.


                  Then the pseudo code would be something like:


                  on setupsprite

                    sprite(1).puppet = true

                    sprite(1).member = member("Foo")

                    sprite(1).scriptInstanceList.add(script("Pixelate").new(1, Arg2, Arg3, Arg4))




                  If that is not clear, ask some more questions.

                  1 person found this helpful
                  • 6. Re: Attatching library behaviors during runtime?
                    nairkat Level 1

                    Thanks for the extended explanations! This is an experiment I'm making on how to incorporate this kind of behaviors dinamically on runtime and in the current state of my project as you will figure is not the top priority untill some other basic stuff in the program gets 100% straightened out (that may take a morning or a couple of days you know). That doesnt mean it's not important, in the contrary. So to be brief, I'm gonna try all that's left to try with the "pixelate" behavior these next few days and will come back with the results. I just wanted to thank you for your participation for now and not let you think I wasnt reading your post

                    • 7. Re: Attatching library behaviors during runtime?
                      nairkat Level 1

                      This is how I have made it to work, finally I think it's necesary to add it to the scriptInstanceList of the same sprite or else (in my testings) won't work. Thanks again! property values can be altered in the new handler but keeping in mind the limits established by the designers for these parameters (check on getPropertyDescriptionList for this).



                      - Calling code from outside:


                             _pixelate= new(script"customPixelate", theGraphicSpNum)

                             add(sprite(theGraphicSpNum).scriptInstanceList, _pixelate)

                             _movie.call(#beginSprite, _pixelate)

                      - Inside a custom version of pixelate:

                           property spriteNum
                           property appearWhen, pixelateDuration, horizontalPixels, verticalPixels, minimumDim


                           on new me, aSpNum -- for implementation via lingo

                             spriteNum= aSpNum 

                             appearWhen = "beginning of sprite" 

                             pixelateDuration = 50

                             horizontalPixels = 3

                             verticalPixels = 3

                             minimumDim = 4

                             return me

                           end new


                      Just for your reference the original behavior is under window/library palette and then animation/sprite transitions/pixelate