Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:32:43+00:00 2026-05-23T11:32:43+00:00

I was wondering what the appropriate form was when creating custom events? Should one

  • 0

I was wondering what the appropriate form was when creating custom events? Should one create a CustomEvent class, and then create a temporary dispatcher in the function, and dispatch the CustomEvent. or is it better to attempt to create a CustomEventDispatcher class, and create the CustomEvent class as an internal class of that class, eg:

package
{

   public class CustomEventDispatcher extends EventDispatcher
   {
     public function CustomEventDispatcher()
     {
       super(new CustomEvent());
     }

   }
}

class CustomEvent
{
   public function CustomEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
   {
      super(type, bubbles, cancelable)
   }                                               
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:32:44+00:00Added an answer on May 23, 2026 at 11:32 am

    There are two basic questions to answer, when conceiving event mechanics.

    1) How do I create dispatcher instance for my events?

    General options are: extend EventDispatcher, or aggregate dispatcher instance.

    Most basic and common practice (and official docs also state that), is extending EventDispatcher class, thus giving your classes event-dispatching capabilities.

    Pros: simple to implement — just type extends EventDispatcher, and you are done.

    Cons: you can’t extend something else. Apparently, this is the reason why many native classes are EventDispatcher’s grandchildren. Just to spare us the trouble, I guess.

    Second general approach is aggregating a dispatcher instance.

    package
    {
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.events.IEventDispatcher;
    
        public class ClassA implements IEventDispatcher
        {
            private var dispatcher:EventDispatcher;
    
            public function ClassA()
            {
                initialize();
            }
    
            private function initialize():void
            {
                dispatcher = new EventDispatcher(this);
            }
    
            public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
            {
                dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
            }
    
            public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
            {
                dispatcher.removeEventListener(type, listener, useCapture);
            }
    
            public function dispatchEvent(event:Event):Boolean
            {
                return dispatcher.dispatchEvent(event);
            }
    
            public function hasEventListener(type:String):Boolean
            {
                return dispatcher.hasEventListener(type);
            }
    
            public function willTrigger(type:String):Boolean
            {
                return dispatcher.willTrigger(type);
            }
        }
    }
    

    Note: we pass a reference to aggregating class to dispatcher constructor.
    This is done to make event.target reference your class instance and not the dispatcher instance itself.

    Pros: you are free to extend whatever you like. You may do some tricks with dispatcher hooks like maintaining listeners list or something alike.

    Cons: not as simple as the first approach.

    2) How do I pass custom data with my events?

    General options are: pass data in an event instance, or only use event.target reference in event handler to access some data from source.

    If you choose to access all necessary data through event.target — no additional work nedded, just cast this reference in event handler to appropriate class.

    If you want to pass some data along with event, you subclass Event, and this class should be publicly visible to the code that handles events, as the answer above states. AS3 is all about strict and strong typing, so why would you resist that?

    Overriding clone() method in an Event subclass is only necessary if you are going to redispatch handled events. The official docs say you must do that every time you create a custom event class, just to be safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if a one-to-one relationship is appropriate for the following scenario: I
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
Two questions. First question is I'm trying to create a simple form that when
I'm wondering the following, the query below will select the appropriate fields if a
I'm writing a multiple choice test taking app and wondering what he most appropriate
I'm taking a Javascript class and was wondering if there was a way to
I was reading the CakePHP manual on $params and was wondering what the appropriate
I'm researching some of the Nuget stuff. I'm wondering if Nuget is appropriate for
I am wondering, how would one write a file (say for instance, from a
I was wondering when is more appropriate to save the view model of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.