4 Replies Latest reply on Nov 21, 2008 1:57 PM by Roland_G

    click event not registering on sprite

    Roland_G
      Here is a simple test code. The generated swf detects a click on the stage but not on the box. Where is the error?
        • 1. Re: click event not registering on sprite
          injpix Level 3
          Are you using Flash’s IDE? I can’t seem to get it to run in Flex but in Flash it runs ok.

          At any rate, you have some redundant code. You only need one addEventListener to accomplish what I believe you want. Remove second addEventListener in the construct and the one in the drawBox method.

          Then replace your clickHandler with the one below and include the import path for it.

          Does this help?
          • 2. click event not registering on sprite
            Roland_G Level 1
            quote:

            Originally posted by: myIP
            Are you using Flash’s IDE? I can’t seem to get it to run in Flex but in Flash it runs ok.



            No, I'm using Flex 3 with FlashDevelop. I have a pure AS3 file which is the one I posted and I compile it. The resulting swf runs fine and displays the box as expected. Only the events aren't working as expected.

            Changing the clickhandler to the version you suggested yields nothing. No trace. But if I change the condition to:
            event.eventPhase == EventPhase.AT_TARGET

            I get the click trace again. My conclusion is that for some reason the event is only registered at the stage and not in the child components(sprite and shape).

            Edit: I'm not using any mxml file, just a pure AS3 file to compile.
            • 3. Re: click event not registering on sprite
              injpix Level 3
              Ok, the attached code below should answer your original question. The problem was that Shape doesn’t inherit from InteractiveObject. I was under the assumption that if a subclass inherits from EventDispatcher it would be interactive. So in your last post, your conclusion was partial right; the stage was listening as expected but descendant (Shape) was not. Now we know.

              So I just added the shape instance to a sprite instance and it works. I also have a listener for Event.ADDED_TO_STAGE. So when ClickTest is actually attached to the stage, then listen for the Mouse.CLICK. Listening for ADDED_TO_STAGE event may be redundant here. I don’t have the experience yet to know when it is needed.
              • 4. Re: click event not registering on sprite
                Roland_G Level 1
                Thanks for you effort myIP, I figured out to make it work but I suspect there is something broken with the AS3 event model. Take a look at this forum post for more information.