10 Replies Latest reply on Mar 6, 2008 2:10 PM by adam@blueapplestudio

    User-defined event assistance needed

    adam@blueapplestudio Level 1
      I have a 3D cast member that contains a bunch of animations defined by start and end points. For example, from 200 to 5000 milliseconds is a rotation animation, and between 5001 and 6000 is a translation animation. I need to know when each of these animations have finished. I used animationEnded initially, but I am not sure how to set animationEnded to fire after a defined span of animation has terminated.

      Do I need to write a custom event to capture this? If so, how do you define an event? I am looking at using registerForEvent, I just don’t know how to write the event itself.

      Any help is appreciated.
        • 1. Re: User-defined event assistance needed
          adam@blueapplestudio Level 1
          If you look up “registerScript” in the online documents ( http://livedocs.adobe.com/director/mx2004/release_update_en/wwhelp/wwhimpl/js/html/wwhelp. htm?href=03_part_.htm) it states the following regarding the eventName parameter:

          “The event can be any of the following predefined events, or any custom event that you define“

          I have figured out a solution to my problem already. I am looping a check to see if the playList is empty. Once the animation is complete, the playList count is 0. However, I would still like to know how to make these “custom events.”

          Has anyone got any experience with this, or am I misinterpreting what a custom event is?
          • 2. Re: User-defined event assistance needed
            code1234 Level 1
            If I understand it correctly...

            a custom event is similar to what you are doing already. You would instead use registerScript to register the name #animationComplete event and an associated script to run with the event occurs. Then when your condition is met (playlist empty) the script associated with the animationComplete event is called. You still have to have a variable or property to check (like playlist) and you still have to check it periodically (like in a frame script). As far as I understand it, it is not like a primary event (i.e. keypress) with all this built in. You still have to define it all with Lingo.

            Anyone out there understand this differently?

            • 3. Re: User-defined event assistance needed
              adam@blueapplestudio Level 1
              code 1234

              Thanks for your response. Could you post a code example of what you are suggesting? Does it go inside of a Movie or Behavior script?
              • 4. Re: User-defined event assistance needed
                adam@blueapplestudio Level 1
                Here is a link to the file I am working on ( http://www.blueapplestudio.com/Director/ and select the file registerSript_customEvent.dir.zip.) On one of the behavior scripts you can see that I am using registerForEvent with animationEnded as the event.

                If you could crack this open and insert your custom event, I'd appreciate it. I just can't get my head around this one.

                Thanks,

                Adam
                • 5. Re: User-defined event assistance needed
                  McFazstp Level 1
                  If you reset the world the animationFinished event only triggers once. Try removing the frame script on "loop1" and changing the behaviour to the following;



                  • 6. Re: User-defined event assistance needed
                    adam@blueapplestudio Level 1
                    McFazstp, thanks for the response. Your code works well, and the event only fires once as you stated. However, I am still trying to figure out the writing of custom events. In your code, #animationEnded is still the event that is triggering the custom handler #playBlueMan.

                    How does one write a custom event that could replace #animationEnded in this example?
                    • 7. Re: User-defined event assistance needed
                      McFazstp Level 1
                      I'm hardly an expert on this. The first time I tried or even heard of this was when I read your post. As far as I can tell the custom event is assigned to the member, not the model, and it is called by using sendEvent. I'm not sure if it can be triggered by the animation itself.

                      member( "BlueMan" ).registerForEvent( #custom_event, #doCustomEvent, me )

                      member( "BlueMan" ).sendEvent( #custom_event )

                      • 8. Re: User-defined event assistance needed
                        adam@blueapplestudio Level 1
                        Thanks, McFazstp. I guess I am still looking for how to craft the actual #custom_event in your example. I have gone through the Director livedocs and not come up with anything.

                        In the sendEvent entry in the livedocs they refer to an event called #jump. This appears to be a custom event, but I don't know how the event is written. Does anyone out there have some experience with this that they could share?

                        For example, let’s say that you have a 2D sprite onstage, and it is rotating through a script. Could you create a custom event that will detect when its rotation is greater than 270? Can one write a custom event that detects when a 3D cast member changes from a “playing” state to a “paused” state? I understand how to register the event, it’s actually writing the event that I am lost on.
                        • 9. Re: User-defined event assistance needed
                          Level 7
                          > For example, let?s say that you have a 2D sprite onstage, and it is rotating
                          > through a script. Could you create a custom event that will detect when its
                          > rotation is greater than 270? Can one write a custom event that detects when a
                          > 3D cast member changes from a ?playing? state to a ?paused? state? I
                          > understand how to register the event, it?s actually writing the event that I am
                          > lost on.

                          I think you're expecting something more than exists.
                          You *the programmer* has to determine when to fire the event. It's not
                          something you can ask to have automatically calculated for you. You have
                          to write code to detect when the rotation goes beyond 270 degrees, or
                          when a 3D sprite's state changes. All of this will involve you polling
                          for information required from a regular event like #exitFrame or a
                          timeout object.
                          When you detect that it's time to fire the event you use
                          member.sendEvent(#eventName)
                          • 10. Re: User-defined event assistance needed
                            adam@blueapplestudio Level 1
                            S. Wilson, you are probably right. It sounds like the place where you actually declare your custom event's name is within sendEvent. This is what I was looking for but probably didn't realize it until now. Thanks for everyone's help and patience.