Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Events in Actionscript 3

  • 01-09-2011 02:20PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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