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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:49:14+00:00 2026-06-14T19:49:14+00:00

Please help me understand how to get custom class instances to access variables defined

  • 0

Please help me understand how to get custom class instances to access variables defined on the timeline.

I am not using a document class, because this program will be a memory experiment with multiple stages, so using the timeline works best for me. (FWIW, I’m also not using xml; just trying to keep this as simple as possible.) For now I’ve just made a simple one-frame fla on which I’m trying to make a vocabulary test. I have made a custom class called VocabQ, which in turn contains 4 instances of a custom class called VocabButton. Right now, clicking one of those buttons just traces the button label. But I want it to also update the value of the String variable CurrentResponse, which is declared on the timeline. If I just try to reference CurrentResponse from the VocabButton class, I get an error “1120: Access of undefined property…”.

I’ve tried a variety of approaches based on discussions I’ve found across the internet, but have not yet had success and am only getting more confused. Please help! (Simple solutions would be greatly appreciated, if such exist!) See code below.
thank you, ~jason

code in timeline:

import VocabQ;
import flash.display.*;
stop();

var CurrentResponse:String="NA";

var VocabQuestion = new VocabQ("VocabWord",["answerA","answerB","answerC","answerD"]);
addChild(VocabQuestion);

VocabQ.as code:

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import VocabButton;

    public class VocabQ extends MovieClip{
        private var _VocabWordText:String;
        private var _VocabWord:TextField;
        private var _ResponseOptions:Array;

        public function VocabQ(VocabWordText:String,ResponseOptions:Array){         
        _VocabWordText=VocabWordText;
        _ResponseOptions=ResponseOptions;
        build();
        }

        private function build():void{          
            _VocabWord = new TextField();
            _VocabWord.text=_VocabWordText;
            _VocabWord.x=25;
            _VocabWord.y=25;
            _VocabWord.textColor = 0x000000;
            addChild(_VocabWord);

            for (var i:int; i < _ResponseOptions.length; i++){
                var _VocabButton:VocabButton = new VocabButton(_ResponseOptions[i]);
                _VocabButton.x = 25 + (_VocabWord.width) + 10 + ((_VocabButton.width + 2) * i);
                _VocabButton.y = 25;
                addChild(_VocabButton);
                }
            }       
    }
}

VocabButton.as code:

package 
{
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;

    public class VocabButton extends MovieClip{
        private var _btnLabel:TextField;

        public function VocabButton(labl:String){

            _btnLabel = new TextField();       
            _btnLabel.textColor = 0x000000;
            _btnLabel.text = labl;
            _btnLabel.border=true;
            _btnLabel.borderColor=0x000000;
            _btnLabel.background=true;
            _btnLabel.backgroundColor= 0xDAF4F0;
            _btnLabel.mouseEnabled = false;
            _btnLabel.selectable=false;
            _btnLabel.width=100;
            _btnLabel.height=18;        
            buttonMode=true;
            useHandCursor=true;
            addEventListener(MouseEvent.CLICK,onClick,false,0,true);

            addChild(_btnLabel);
        }

        private function onClick(evt:MouseEvent):void{
        trace(_btnLabel.text);  
        //CurrentResponse=_btnLabel.text;  //causes error 1120: Access of undefined property...
        }
    }
}
  • 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-14T19:49:16+00:00Added an answer on June 14, 2026 at 7:49 pm

    This should work:

    private function onClick(evt:MouseEvent):void {
        trace(_btnLabel.text);  
        evt.currentTarget.root.CurrentResponse=_btnLabel.text;
    }
    

    See the discussion here: http://www.actionscript.org/forums/showthread.php3?t=161188

    Personally, rather than trying to access the timeline like this, I would prefer to add a click listener
    to your VocabQuestion on the timeline and allow the Event to Bubble Up, or, if you are going to have a number of buttons within your class, to extend EventDispatcher and create some custom events which can likewise be handled on your timeline, but for a simple test, accessing the root property should be good enough.

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

Sidebar

Related Questions

the following code is not behaving like I would expect. Please help me understand
Can anyone please help me to understand how should i access json data in
Can anyone help me please? I'm using VS2010, C++ Custom Action Project. Trying to
Someone please help me understand why this binding does not work... I have a
Can you please help me understand the adapter with custom data : I was
I'm new to smart-card development. Please help me understand how to get started. What's
Could someone please help me to understand how to get all parameters passed to
Please help me understand the following code snippet :- def any(l): whether any number
Please help me understand why add1() and add4() report errors and why add2() and
Please help me understand this recursive function... var stack = Array; function power(base, exponent){

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.