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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:24:09+00:00 2026-06-09T16:24:09+00:00

This has been bugging me for a few days now. I have written a

  • 0

This has been bugging me for a few days now. I have written a multi-functional messageBox class, and it works pretty well, but there’s one thing I’m stuck on. First, though, here’s some code:

in the document class I have:

var tMsg:Msg = new Msg("Test Message", "This is a test Message", Msg.INPUT);

tMsg.addEventListener('Answered', qa, false, 0, true);

function qa(e:Event):void{
    trace(e.target.label,e.target.result);
    tLabel.label = e.target.result;
}

When either the ‘cancel’ or ‘ok’ buttons are clicked, the result property is set and the ‘Answered’ event is dispatched. Since this event listener will always need to be added, I thought it would be better to include it within the class constructor; however, each instance of the Msg class would need its own callback, depending on what the result is being used for. Also, the callback functions should be declared in the document class.

I thought this could be accomplished by simply passing the function to the Msg class constructor, and then use that reference to generate the addEventListener dynamically.
For example:

/// in document class
var tMsg:Msg = new Msg("Test Message", "This is a test Message", Msg.INPUT, qa);

function qa(e:Event):void{
    trace(e.target.label,e.target.result);
    tLabel.label = e.target.result;
}

/// in Msg class
public function Msg(txt:String='', msg:String='', type:String=ALERT, callback:Object=null) {
    _callback = callback;
    addEventListener(Event.ADDED, setup, false, 0, true);
}
private function setup(e:Event){
    stage.addEventListener('Answered', _callback, false, 0, true);
}

This doesn’t work. I don’t know if it’s because I’m trying to store the callback reference (the event listener should be added to the stage object) or what? The upside to getting this to work would be I wouldn’t have to add an event listener each time I create a new message, just pass along the associated function.

Thank you in advance for any help you could provide me.

  • 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-06-09T16:24:10+00:00Added an answer on June 9, 2026 at 4:24 pm

    You should add the event listener to the object that dispatches the event. If that object isn’t on the display list or the event doesn’t bubble then the stage will not receive the event.

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

Sidebar

Related Questions

This has been bugging me for a few days now and I have not
This has been bugging me for a few days now. I'm trying to migrate
This has been bugging me for more than two days now, so i thought
This issue has been on/off bugging me and I've written 4 wrappers now. I'm
This has been bugging me lately. Say I have a base class Base. If
This has been bugging me for a couple days now. A list has content
This has been bugging me for the last few hours now. I am using
This has been bugging me for 2 days now and I cant get my
This question has been bugging me for a long time now but essentially I'm
This Jquery problem has been bugging me for a while now. I developed a

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.