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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:47:38+00:00 2026-05-23T00:47:38+00:00

For reference, here’s a question I asked earlier today regarding this same project: Reference

  • 0

For reference, here’s a question I asked earlier today regarding this same project: Reference objects on stage/frame from document class

addFrameScript seems to do what I need it to, except for one thing. In the function I’m passing to be added as a frame script, I want to dynamically create some event listeners for buttons, but variables I want closed over the listener functions aren’t behaving as expected — they all end up having the last assigned value of the variable rather than the value it had when the function was defined, as if different scope rules are in effect than normal:

addFrameScript(node_frame - 1,
    function() {
        stop();
        question_txt.text = node_question;
        answers_xml = node_xml.answer;
        for (var i:Number = 0; i < answers_xml.length(); i++) {
            button = getChildByName('answer' + (i+1) + '_btn');
            if (answers_xml[i].attribute('node')) {
                goes_to = answers_xml[i].attribute('node');
                trace(goes_to); 
                button.addEventListener('click',
                    function() {
                        trace(goes_to);
                    });
            }
        }                   
    });

The trace output at first is:

1A
2A
3A

But then afterward, if I click any of the three buttons, they all trace:

3A

Anyone have any insight to what’s going on here and/or how I can work around it? Do frame scripts observe different (dynamic rather than lexical?) scoping or something?

  • 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-23T00:47:38+00:00Added an answer on May 23, 2026 at 12:47 am

    No, scoping in added frame scripts behave exactly like scoping everywhere else in AS3. Flash late-binds variables, but you’re trying to access them as though they’re early-bound inside your listener.

    Oddly enough, I just answered this same question earlier today here: How do you bind a variable to a function in as3

    For more information, I wrote a blog post about this sort of thing here: http://www.scriptocalypse.com/?p=31

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

Sidebar

Related Questions

This is in reference to the question previously asked The problem here is, each
I was trying to answer the question mentioned here by passing the reference to
Refer original post here for a reference to the original issue. What plugin should
I would like to cross-reference construct a distance chart similar to the one here
I'm having a problem adding a reference to a .NET assembly I built. Here's
So here is my problem. My (test) project references both Castle Windsor and Rhino
I know there are a LOT of similar question to this, but I've tried
I am rewriting a project so that it uses getters and setters to reference
Reference here That destructor will also implicitly call the destructor of the auto_ptr object.
For reference here is what my web.config and code look like: <membership defaultProvider=SqlProvider userIsOnlineTimeWindow=15>

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.