Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Events in Actionscript 3

Options
  • 01-09-2011 3:20pm
    #1
    Registered Users Posts: 8,449 ✭✭✭


    Hey, I'm having trouble getting some sample events working in as3.

    Everything is fine if i'm say handling a mouse click event in a main class, I just add the mouse-click event listener and specify the function to use and when the mouse is clicked it gets called. That's fine.

    But what I don't understand is why it isn't working between classes.

    Say I have a Scene class that tests for collisions between the Player and all other objects. When the sprite hitTest function returns true I want to dispatch and event to the player class. so in the Scene class I'm calling something like dispatchEvent(CollisionEvent). In the player class I tried to add an event listener function for a CollisionEvent and I provided a function that traces if the Player class receives the event.

    I even tried making the player object the target of the EventDispatcher but no dice.

    I don't understand what I'm not understanding. Surely you can send an event from one class to another, I just can't seem to figure out the flow of events in actionscript...

    Anyone have any experience with this, shed any light? I've been looking online but can't find any decent information.

    Thanks


Comments

  • Registered Users Posts: 10,148 ✭✭✭✭Raskolnikov


    So you're firing an event from the Scene class that you expect to be listened to by the Player class?

    Could it be that you haven't actually instantiated the Player class? You can test this by adding the below line to where you're calling addEventListener() in your Player class.

    trace("Event listener added");

    Apologies if this is too obvious, but it was the first thing that came to mind!


Advertisement