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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:14:18+00:00 2026-05-24T02:14:18+00:00

i am having trouble understanding how to dispatch events and where to catch them.

  • 0

i am having trouble understanding how to dispatch events and where to catch them. currently i have a document class waterMain, and another class called gunner. my waterMain createds a object of gunner and adds it as child, in my gunner there is a function firebullet, in it i dispatch a

dispatchEvent(new Event(“bulletFired”));

and from my waterMain class i do a

    addEventListener("bulletFired", bulletFiredHandler); 
    private function bulletFiredHandler(e:Event):void       
{           
hudMenu.reduceBullet();         
}

the hudMenu is a variable on the waterMain document class, however it seems that nothing is happening. is the waterMain class not catching the dispatched event?

package  
{
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    /**
     * ...
     * @author ...
     */
    public class Gunner extends MovieClip
    {
        private var _stageRef:Stage;
        public var barrel:MovieClip;
        public var point:MovieClip;
        public var _hudMenu:HUD;

        public function Gunner(stageRef:Stage) 
        {   

            //trace("current rotation" + barrel.rotation);
            //barrel.rotation = -90;
            _stageRef = stageRef;
            addEventListener(Event.ENTER_FRAME, rotateTurret);
            _stageRef.addEventListener(MouseEvent.MOUSE_DOWN, fireBullet);


        private function rotateTurret(evt:Event):void 
        {
            //calculations, distance, angle etc
            var a:Number = _stageRef.mouseX - x;
            var b:Number = _stageRef.mouseY - y;
            var angRad:Number = Math.atan2(b, a);
            var angDeg:Number = (angRad * 180 / Math.PI);
            //trace(angDeg );

            barrel.rotation = (angDeg);
        }
        private function fireBullet(mouseEvt:MouseEvent):void
        {

            dispatchEvent(new Event("bulletFired"));
            _stageRef.addChildAt(new Bullet(_stageRef,x, y , new Point(mouseEvt.stageX, mouseEvt.stageY), _koiArray, _lionArray), 1);
            _stageRef.addChild(_stageRef.addChild(this));
        }
    }

}
  • 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-24T02:14:19+00:00Added an answer on May 24, 2026 at 2:14 am

    You need to add the event to the gunner class something like this:

    gunner.addEventListener("bulletFired", bulletFiredHandler);
    

    The gunner class is already a EventDispatcher subclass, if I read your question correctly.

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

Sidebar

Related Questions

I'm having trouble understanding using D3 events and dispatch functions. I have a chart
Im having trouble understanding class relationships after being asked to research it further, would
I am having trouble understanding how layering is performed within Xcode. I have a
I'm having trouble understanding why I have to place the button triggering the getJSON
I'm having trouble understanding coredata with my uitableview. I have rows being deleted and
Im having trouble understanding this class and everything ive seen hasn't really helped. Ill
I'm having trouble understanding why a click event bound to the document would be
I'm having trouble understanding the jQuery pushStack function (documented at http://api.jquery.com/pushStack/ ). I have
I'm having trouble understanding this behaviour of the Ruby Matrix class, is it just
I'm having trouble understanding what happens when a ToArray() is called on an IEnumerable.

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.