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

  • Home
  • SEARCH
  • 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 3244720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:35:06+00:00 2026-05-17T18:35:06+00:00

ActionScript 3, just learning AS3 but know a handful of other languages. What would

  • 0

ActionScript 3, just learning AS3 but know a handful of other languages.

What would cause an event that the listen call executes without throwing an error and was successfully dispatched, to not be listened to?
dispatch call (this runs ):

private function HandleMouseClick( e:Event ):void{
if ( m_MouseState == MOUSE_STATE_SELECTED )
    m_MouseState = MOUSE_STATE_NONE;
else
{
    m_MouseState = MOUSE_STATE_SELECTED;
    var evt:PlayerMoveFinishedEvent =  new PlayerMoveFinishedEvent( m_uiValue, Operation.ADDITION );
    var result:Boolean = dispatchEvent( evt );
    trace(result);
}

m_bDirty = true;

}

Listen call (this runs ):

addEventListener( PlayerMoveFinishedEvent.MOVE_FINISHED, HandlePlayerMove );

Handler (never called ):

public function HandlePlayerMove( e:PlayerMoveFinishedEvent ):void{trace("received!");}

message:

public class PlayerMoveFinishedEvent extends Event 
{
    public static const MOVE_FINISHED:String = "MoveFinished111wefsdsdvs";
    private var m_uiValue:uint;
    public var m_Operation:uint;

    public function PlayerMoveFinishedEvent( _uiValue:uint, _Operation:uint ) 
    { 
        super( PlayerMoveFinishedEvent.MOVE_FINISHED);

        m_uiValue = _uiValue;
        m_Operation = _Operation;

    } 

    public function get Value():uint 
    {
        return m_uiValue;
    }

    public function get Operation():uint
    {
        return m_Operation;
    }

    public override function clone():Event 
    { 
        return new PlayerMoveFinishedEvent( m_uiValue, m_Operation );
    } 

    public override function toString():String 
    { 
        return formatToString("PlayerMoveFinishedEvent", "type", "bubbles", "cancelable", "eventPhase"); 
    }

}

(sorry about the formatting, i blame the preview )

update:
ok, here’s the fulll listener class:

public class MoveTracker extends Sprite
{
    private var m_kCurrentOperation:Operation = null;
    private var m_uiTotalMoves:uint = 0;

    public function MoveTracker() 
    {
        super();
        var s:String = PlayerMoveFinishedEvent.MOVE_FINISHED;
        addEventListener( s, HandlePlayerMove );
    }

    public function HandlePlayerMove( e:PlayerMoveFinishedEvent ):void
    {
        var runningTotal:uint = 0;
        if ( m_kCurrentOperation != null )
            runningTotal = m_kCurrentOperation.RunningTotal;

        m_kCurrentOperation = new Operation( runningTotal, e.Value, e.Operation, m_kCurrentOperation );
        // draw in the right spot.
        m_kCurrentOperation.y = m_uiTotalMoves * m_kCurrentOperation.y;
        m_uiTotalMoves++;
        addChild( m_kCurrentOperation );
    }


}

now the place class where its added can be reuced to the necessary:

public class Square extends Sprite{     
private static var MOUSE_STATE_NONE:uint = 0;
private static var MOUSE_STATE_HOVER:uint = 1;
private static var MOUSE_STATE_SELECTED:uint = 2;

… other variables here …

public function Square(_x:Number, _y:Number, fWidth:Number, fHeight:Number, colour:uint, value:uint) 
{   
    super();
    x = _x;
    y = _y;


    m_kSize = new Point( fWidth, fHeight );
    m_uiColour = colour;
    m_uiSelectedColour = 0xFF80C0;
    m_uiHoverColour = 0x9BDB88;
    m_uiValue = value;


    var kTextDisplay:Bitmap;
    var kTextDisplayData:BitmapData;            
    kTextDisplayData = new BitmapData(m_kSize.x, m_kSize.y, true, 0x00FFFFFF);
    DText.draw( kTextDisplayData, m_uiValue.toString(), 0, 0, DText.LEFT );
    kTextDisplay = new Bitmap( kTextDisplayData );

    // position the number in the centre of the square.
    kTextDisplay.x = m_kSize.x * 0.5 - ( 8 * ( m_uiValue.toString().length * 0.5 ) ) ;
    kTextDisplay.y = m_kSize.y * 0.5 - 8;
    addChild( kTextDisplay );

    m_MouseState = MOUSE_STATE_NONE;

    addEventListener(MouseEvent.MOUSE_OVER, HandleMouseEnter);
    addEventListener(MouseEvent.MOUSE_OUT, HandleMouseExit);

    addEventListener(MouseEvent.CLICK, HandleMouseClick );

    addEventListener(Event.RENDER, Draw );

    m_bDirty = true;
}
private function HandleMouseClick( e:Event ):void 
{
    if ( m_MouseState == MOUSE_STATE_SELECTED )
        m_MouseState = MOUSE_STATE_NONE;
    else
    {
        m_MouseState = MOUSE_STATE_SELECTED;
        var evt:PlayerMoveFinishedEvent =  new PlayerMoveFinishedEvent( m_uiValue, Operation.ADDITION );
        var result:Boolean = dispatchEvent( evt );

    }

    m_bDirty = true;
}

}

the “Squares” are childed to a checkerboard that is childed to my main app ( which extends sprite ). the checkerboard displays and has all the behaviour i want, but when i click a square, the click event fires and dispatches the custom event, but the custom event is never received.

that should be all code needed, the rest of the code is just to create a grid and put random numbers in the squares, which works fine.

any advice is appreciated! 🙂

according to every website that has a “custom event tutorial” it would appear that i have everything needed to listen to the event, its just not happening 🙁

  • 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-17T18:35:06+00:00Added an answer on May 17, 2026 at 6:35 pm

    In order to answer your question, we need to know who’s dispatching the event & where/when you add your event listener.

    Why is your HandlePlayerMove listener a public function?

    You could try a different approach where you would use a dispatcher in the Square class that would listen to the custom event in the checkerboard class.

    // In your Main Class, you create a new instance of an EventDispatcher
    // and pass it as a parameter to the children
    public class Main extends Sprite
    {
        private var dispatcher:EventDispatcher;
    
        public function Main()
        {
           dispatcher = new EventDispatcher();
           dispatcher.addEventListener( PlayerMoveFinishedEvent.MOVE_FINISHED, 
                    HandlePlayerMove )
        }
        // later in your code when you create a Square
        var square = new Square(dispatcher );
    }
    
    public class Square extends Sprite
    {
         private var _dispatcher:EventDispatcher;
    
         public function Square(dispatcher:EventDispatcher):void
         {
             this._dispatcher = dispatcher;
         }
    
         //etc....
    
         private function HandleMouseClick( e:Event ):void 
         {
           //.... your code here
            _dispatcher.dispatchEvent( evt );
           //.... your code here
         }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an actionscript file that defines a class that I would like to
In ActionScript, how can you test if an object is defined, that is, not
I knew ActionScript and ActionScript2 inside out, but I've been away from Flash for
I have an ActionScript 2.0 file that contains a small library. This library parses
ActionScript 3 / Flex 3 - Adding custom events to a class Say I
Since Actionscript is a proper superset of javascript, it should I suppose be possible.
Is it possible in Actionscript 3 to create a weak reference to an object,
In an actionscript function (method) I have access to arguments.caller which returns a Function
I am working on an Actionscript 2 project - trying to use the XML
How do I Configuring DoxyGen to document ActionScript files? I've included the *.as and

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.