A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Passing events out of a class

  1. #1
    Member
    Join Date
    Jan 2004
    Location
    England
    Posts
    87

    Passing events out of a class

    Hello all,

    So I've created a custom class which makes use of a Sound object. The Sound object loads a sound from a URL, and I attach and event listener to it to see it when it finishes loading i.e. Event.Complete

    MY question is this: how do I receive this event outside of the class? For instance, I want to be able to create an instance of my class somewhere else, load a sound and attach an event listener to my custom class that listens for the event thrown by the sound. Understandably, I don't want to make the sound object a public variable. So does anyone have any idea what to do?

    THanks in advance,
    j

    my code is crap

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The custom class can re-dispatch the event, or dispatch its own event as a response to the sound events. Other classes can then attach listeners to your custom class instance.

  3. #3
    Member
    Join Date
    Jan 2004
    Location
    England
    Posts
    87
    Quote Originally Posted by 5TonsOfFlax View Post
    The custom class can re-dispatch the event, or dispatch its own event as a response to the sound events. Other classes can then attach listeners to your custom class instance.
    Sounds perfect! Do you know any good pages with info about redispatching events??

    THanks,
    j

    my code is crap

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Simply make sure your custom class is an IEventDispatcher (you can extend EventDispatcher if you need a baseclass) and call dispatchEvent with the same event.

    There really isn't a lot to it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center