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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:54:51+00:00 2026-05-14T00:54:51+00:00

I’ve used the GUI to create a rectangle that I turned into a button

  • 0

I’ve used the GUI to create a rectangle that I turned into a button symbol (SimpleButton). I then edited the button so that it had 4 different button states and a text layer on top. I then created a class definition file for this object so that I could dynamically change the label text (the text layer) when adding instances of this button to the stage.

I was able to create and link a class file (DynamicButton.as) just fine, but when I try to access the text field that I created on the button, I get the error:

“Access of possibly undefined property btnLabel through a reference with static type com.examples:DynamicButton.”

when i couldn’t get that to work, I decided I’d try adding the TextField directly within the class definition file, using the following code:

package com.examples 
{
    import flash.display.Sprite;
    import flash.display.SimpleButton;
    import flash.text.TextField;

    public class DynamicButton extends SimpleButton
    {
        public function DynamicButton(btnText:String="Click Me")
        {
            placeText();
            labelText.text = btnText;           
        }

        //property variables
            //create a text box to hold the button label
            private var labelText:TextField = new TextField();
            //create a displayObject to hold the text
            private var labelSprite:Sprite = new Sprite();      

        private function placeText():void {
            labelText.width = this.width;
            labelText.height = this.height;
            labelText.x = this.x;
            labelText.y = this.y;
            labelText.visible = true;
            labelSprite.addChild(labelText);
            this.parent.addChild(labelSprite);
        }

    }
}

The problem is that I can’t seem to add the TextField to the SimpleButton, as it’s not a display object. So, I tried adding it to the parent of the simple button (and I figured, I’d just place it exactly above the button). But then I get a “null object reference.” error.

So, I have two questions

  1. is there a way to access GUI-created elements from w/i a class definition file?
  2. How would I add the TextField to the button using only AS3 inside of a my class definition file?
  • 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-14T00:54:52+00:00Added an answer on May 14, 2026 at 12:54 am

    OK, it took a few days and some introspection, but it seems that the problem I’ve having stems from the fact that you cannot add children to a SimpleButton. I changed my class definition to extend a MovieClip, then created a function named “listen()” that I called when constructing the object that added listeners for the “over”,”down”, and “out” mouse states, so as to imitate a simple button. I also had to put a “stop()” command in the constructor, so that each button wouldn’t keep cyclying through all the states. The final class definition looks like this:

    package com.examples 
    {
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
    
        public class DynamicButton extends MovieClip
        {
            public function DynamicButton(btnText:String="Click Me")
            {
                stop(); 
                this.btnText_btn.text = btnText;
                listen();
            }//constructor  
    
            private function listen():void {
                this.addEventListener(MouseEvent.MOUSE_OVER,function(){
                        gotoAndStop(2);
                    }//anon mouseover fcn
                );
                this.addEventListener(MouseEvent.MOUSE_DOWN,function(){
                        gotoAndStop(3);
                    }//anon mousedown fcn
                );
                this.addEventListener(MouseEvent.MOUSE_OUT,function(){
                        gotoAndStop(1);
                    }//anon mouseout fcn
                );          
            }
        }//class definition
    }//package
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I used javascript for loading a picture on my website depending on which small
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.