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 4258130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:36:29+00:00 2026-05-21T05:36:29+00:00

I dispatch a custom event from an event dispatcher (following solution Inherited a class

  • 0

I dispatch a custom event from an event dispatcher (following solution Inherited a class from EventDispatcher in Flash but custom event not received) and I add a listener in both dispatcher itself and in main. trace shows that only dispatcher receives this event not main. How to make main also receive the event ?

package 
{
    import flash.display.Sprite;
    import flash.events.Event;

    public class main extends Sprite 
    {
        private var _sliderSprite:SliderSprite;

        public function main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);

        }// end function

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            _sliderSprite = new SliderSprite();
            _sliderSprite.x = (stage.stageWidth / 2);
            _sliderSprite.y = (stage.stageHeight / 2);
            addChild(_sliderSprite);
            this.addEventListener(CustomEvent.CUSTOM_EVENT_TYPE, onCustomEventType);

        }// end function

        private function onCustomEventType(e:CustomEvent):void
        {
                    // never triggered
            trace("hello");

        }// end function

    }// end class


}// end package

class 2

package {

    import flash.display.Sprite;
    import flash.events.IEventDispatcher;
    import fl.controls.Slider;

    public class SliderSprite extends Sprite
    {
        private var _slider:Slider;
        private var _eventDispatcherManager:EventDispatcherManager;

        public function SliderSprite()
        {
            init();

        }// end function

        private function init():void
        {
            _slider = new Slider();
            addChild(_slider);

            _eventDispatcherManager = new EventDispatcherManager(IEventDispatcher(_slider));

        }// end function

    }// end class

}

class 3

package {

import fl.controls.Slider;
import fl.events.SliderEvent;
import flash.events.*;

internal class EventDispatcherManager extends EventDispatcher
{
    public function EventDispatcherManager(slider:IEventDispatcher)
    {
        slider.addEventListener(SliderEvent.CHANGE, onSliderChange);
        this.addEventListener(CustomEvent.CUSTOM_EVENT_TYPE, onCustomEventType);

    }// end function

    private function onSliderChange(e:SliderEvent):void
    {
        this.dispatchEvent(new CustomEvent(CustomEvent.CUSTOM_EVENT_TYPE, e.value));

    }// end function

    private function onCustomEventType(e:CustomEvent):void
    {
        // triggered
        trace(e.value);

    }// end function

}// end function

}

class 4

package  {
import flash.events.Event;

internal class CustomEvent extends Event
{
    public static const CUSTOM_EVENT_TYPE:String = "customEventType";
    private var _value:Number;

    public function get value():Number
    {
        return _value;

    }// end function

    public function CustomEvent(type:String, 
                                value:Number,
                                bubbles:Boolean = false,
                                cancelable:Boolean = false)
    {
        _value = value;

        super(type, bubbles, cancelable);

    }// end function

    override public function clone():Event
    {
        return new CustomEvent(type, value, bubbles, cancelable);

    }// end function

}// end class

}
  • 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-21T05:36:29+00:00Added an answer on May 21, 2026 at 5:36 am

    In order for your instance of the main class to recieve events from the EventDispatcherManager, you have to register main as a listener with the EventDispatcherManager.

    Something like:

    //in main:
    sliderSprite.eventDispatcherManager.addEventListener(CustomEvent.CUSTOM_EVENT_TYPE,onCustomEvent);
    

    But for that to work you would have to either set the _eventDispatcherManager propterty as public och make it accessible through an accessor, or a simple get-function.

    Though I would strongly recommend you to look over the structure. By the look of it you could skip the EventDispatcherManager class and the CustomEvent class, and just dispath the value directly from the SliderEvent to Main.

    But this is maybe just a Demo example?

    Edit:

    This is what a getter function would look like:

    function get eventDispatcherManager():EventDispatcherManager {
           return _eventDispatcherManager;
    }
    

    Put that function in your SliderSprite class and call it from Main just as I described above.

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

Sidebar

Related Questions

I tried to dispatch a custom event from some component on the stage and
I am trying to dispatch a custom event from one flex module to another.
Eventdispatching here we are again... I'm trying to dispatch a custom event from an
In a FLEX app, I am trying to re-dispatch a custom event. I.e. component1
I have a custom event class public class FFTDrawEvent extends Event { public static
I have created a custom even class which is pretty basic. But when calling
Basically I'm trying to dispatch a custom made mouse click event to a text
How do I correctly implement custom events? I thought the following should work, but
Say I have a class with a private dispatch table. $this->dispatch = array( 1
Here's a snippet of code from within TurboGears 1.0.6: [dispatch.generic(MultiorderGenericFunction)] def run_with_transaction(func, *args, **kw):

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.