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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:32:24+00:00 2026-05-21T14:32:24+00:00

I have a button instance named Button that I have in my movie, this

  • 0

I have a button instance named Button that I have in my movie, this instance has a Dynamic Text object in it named myText, how can I change the text? I already tried Button.myText.text = “Stuff”;

I get the error “Scene 1, Layer ‘Layer 1’, Frame 1, Line 7 1119: Access of possibly undefined property myText through a reference with static type flash.display:SimpleButton.” When I compile.

AS:

import flash.events.MouseEvent;

TheButton.addEventListener(MouseEvent.CLICK, onClick);

function onClick(Event:MouseEvent):void{
    TheButton.myText.text = "Moo";
}
  • 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-21T14:32:25+00:00Added an answer on May 21, 2026 at 2:32 pm

    You can’t use the dot syntax to access a display object container’s child display objects in AS3 as you did in AS2. Normally you would use the display object container’s getChildByName() method to get its child display objects, but because your dealing with an instance of SimpleButton which is a subclass of DisplayObject that method doesn’t exist. The simple solution is to change you button from a button to a movieclip after which the following should work:

    TheButton.addEventListener(MouseEvent.CLICK, onClick);
    
    function onClick(Event:MouseEvent):void
    {
        TheButton.getChildByName("myText").text = "Moo";
    
    }
    

    Note: the TextField display object in the TheButton display object container must have an instance name of “myText” and obviously the TheButton display object container must have an instance name of “TheButton”.

    Also if your going with this approach you may want to rewrite the code as follows:

    import flash.display.DisplayObjectContainer
    import flash.events.MouseEvent;
    import flash.text.TextField;
    
    button.addEventListener(MouseEvent.CLICK, onButtonClick);
    
    function onButtonClick(e:MouseEvent):void
    {
        var button:DisplayObjectContainer = DisplayObjectContainer(e.target);
        var textField:TextField = TextField(button.getChildByName("textField"));
        textField.text = "Moo";
    
    }// end function
    

    [UPDATE]

    Another solution is to create a movieclip/sprite object for the SimpleButton object’s upState, overState and downState properties like the following:

    import flash.display.DisplayObjectContainer;
    import flash.display.SimpleButton;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    
    var simpleButton:SimpleButton = new SimpleButton();
    addChild(simpleButton);
    
    var content:Sprite = new Sprite();
    draw(content.graphics, 0xFF0000);
    
    var textField:TextField = new TextField();
    textField.name = "textField";
    textField.text = "UP";
    content.addChild(textField);
    
    simpleButton.upState = content;
    simpleButton.overState = content;
    simpleButton.downState = content;
    simpleButton.hitTestState = content;
    
    simpleButton.addEventListener(MouseEvent.MOUSE_OVER, onSimpleButtonMouseOver);
    simpleButton.addEventListener(MouseEvent.MOUSE_DOWN, onSimpleButtonMouseDown);
    simpleButton.addEventListener(MouseEvent.MOUSE_OUT, onSimpleButtonMouseOut);
    simpleButton.addEventListener(MouseEvent.MOUSE_UP, onSimpleButtonMouseUp);
    
    function onSimpleButtonMouseOver(e:MouseEvent):void
    {
        var content:DisplayObjectContainer = DisplayObjectContainer(SimpleButton(e.target).overState);
        var textField:TextField = TextField(content.getChildByName("textField"));
        textField.text = "OVER";
        draw(content.graphics, 0xC8C8C8);
    
    }// end function
    
    function onSimpleButtonMouseDown(e:MouseEvent):void
    {
        var content:DisplayObjectContainer = DisplayObjectContainer(SimpleButton(e.target).downState);
        var textField:TextField = TextField(content.getChildByName("textField"));
    
        textField.text = "DOWN";
        draw(content.graphics, 0x646464);
    
    }// end function
    
    function onSimpleButtonMouseUp(e:MouseEvent):void
    {
        var content:DisplayObjectContainer = DisplayObjectContainer(SimpleButton(e.target).overState);
        var textField:TextField = TextField(content.getChildByName("textField"));
    
        textField.text = "OVER";
        draw(content.graphics, 0xC8C8C8);
    
    }// end function
    
    function onSimpleButtonMouseOut(e:MouseEvent):void
    {
        var content:DisplayObjectContainer = DisplayObjectContainer(SimpleButton(e.target).upState);
        var textField:TextField = TextField(content.getChildByName("textField"));
    
        textField.text = "UP";
        draw(content.graphics, 0xFF0000);
    
    }// end function
    
    function draw(graphics:Graphics, color:uint):void
    {
        graphics.clear();
        graphics.beginFill(color)
        graphics.drawRect(0, 0, 100, 100);
        graphics.endFill();
    
    }// end function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I load a single instance of a window on php-gtk, I have a button
I have a button that I would like to disable when the form submits
I have a button on an ASP.Net page that will call Response.Redirect back to
I have a button on a website that creates a directory and copys a
I have a Button that is looking at 2 comboboxes to make sure they
Named instance of SSAS 2005. I can ping the machine by name, IP, and
I have a button on an ASP.NET wep application form and when clicked goes
I have a button inside an updatepanel. I have a PopupControlExtender linked to the
I have a button with a transparent background on a wpf window. Problem is,

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.