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

The Archive Base Latest Questions

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

O.K. Here’s the situation… I have a custom mxml component that contains a couple

  • 0

O.K. Here’s the situation…

I have a custom mxml component that contains a couple of images and 4 buttons. The component file already contains a clickHandler for each of the buttons. I need to be able to either access the clickHandler or create another function and attach it to those buttons from within my Main.mxml file. Should I add to the original clickHandlers? if so, how do I apply the method to my Main.mxml file?

FYI: The component has 5 states and each clickHandler triggers transitions between the states.

Here are the two clickHandlers from the component file:

protected function submit_clickHandler():void
        {
            const state:String = currentState;
            if ( state == 'state1' ) {
                currentState='state2';
            }
            if ( state == 'state3' ) {
                currentState='state4';
                addElement(images[i]);     //The methods I want to run from 
                getStudentAnswer();        //within the Main.mxml.
                submit();                  //If I add them here, I get an
                newQuestion();             //undefined method error.
            }
            if ( state == 'state4' ) {
                currentState='state4';
            }
            if ( state == 'state5' ) {
                currentState='state4';
            }
            if ( state == 'state3' ) {
                Sequence1.play();
            }
        }

        protected function checkAnswer_clickHandler():void
        {
            const state:String = currentState;
            if ( state == 'state2' ) {
                currentState='state1';
            }
            if ( state == 'state4' ) {
                currentState='state5';
            }
        }

Thanks,
JM

  • 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-21T19:20:30+00:00Added an answer on May 21, 2026 at 7:20 pm

    If you have access to the dispatch event for the buttons, just set “bubbles” to “true” and listen for the event in Main.mxml. If you think of the display list as a hierarchal tree with branches, an event that bubbles will travel up the branch until it reaches the first DisplayObject. Along the way, it checks each DisplayObject to find if it is waiting to capture the event.

    Here is a basic illustration where Main is listening for a click event and has a child MovieClip instance with a child Sprite instance. The Sprite instance has a child Button instance that is dispatching a click event.

    [object Main] (listening for MouseEvent.CLICK)
          |
          |__[object MovieClip]
                    |
                    |___[object Sprite]
                              |
                              |____[object Button] (dispatching MouseEvent.CLICK)

    The dispatched click event in Button would be:

    dispatchEvent(new MouseEvent(MouseEvent.CLICK, true));

    In Main, you would just listend for the event:

    addEventListener(MouseEvent.CLICK, clickHandler);

    Because MouseEvent.CLICK is such a common event, I would suggest creating a custom event (or at least a unique event name) in this type of scenario to avoid the possibility of DisplayObject’s capturing incorrect events. But, hopefully this gives a better idea of how to handle bubbling.

    –

    Without bubbling, the only other way to capture the event would be to use dot syntax. I don’t recommend this method because it could get messy, but this helps to illustrate the concept of bubbling (assuming each child DisplayObject is public):

    In Main: (again, not recommended)

    movieClip.sprite.button.addEventListener(MouseEvent.CLICK, clickHandler);

    Hope that helps!

    [EDIT – Added custom Event]
    Here is what a custom Event class would look like:

    package com.example.events
    {
        import flash.events.Event;
    
        public class CustomEvent extends Event {
    
            public static const WITH_DATA:String = "withData";
    
            public var data:Object;
    
            public function NavEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) {
                super(type, bubbles, cancelable);
                this.data = data;
            }
        }
    }
    

    You would then dispatch an event like:

    var myString:String = "buttonState";
    dispatchEvent(new CustomEvent(CustomEvent.WITH_DATA, myString, true));
    

    And listen for the event like:

    addEventListener(CustomEvent.WITH_DATA, customEventHandler);
    
    private function customEventHandler(e:CustomEvent):void {
        trace(e.data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my situation: I have a Data Template set up which contains a ToggleButton
Here is my problem...I have a page that loads a list of clients and
Here is an example: I have a file 1.js, which has some functions. I
Here is my situation: I am using telerik with winform. I have a dataset
Here is my code (Say we have a single button on the page that
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here's the context: I have a file (or stream), and I want to process
Here's the thing: I want to add some images programmatically. The images should have
Here is the situation, I am attempting to fire a set of Gallio tests

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.