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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:35:40+00:00 2026-05-21T05:35:40+00:00

Created a button, now tried to add it to the screen and im getting

  • 0

Created a button, now tried to add it to the screen and im getting this error. The code for the button is –

private function submitButton():void {
  submit_button=new SimpleButton();
  submit_button.x=200;
  submit_button.y=200;
  submit_button.upState=buttonShape();
  submit_button.overState=buttonShape();
  submit_button.downState=buttonShape();
}

private function buttonShape() {
  var rectangle:Shape = new Shape; // initializing the variable named rectangle
  rectangle.graphics.beginFill(0x8C2B44); // choosing the colour for the fill, here it is red
  rectangle.graphics.drawRect(200, 200, 300,20); // (x spacing, y spacing, width, height)
  rectangle.graphics.endFill();
}

I’ve declared it as a public var and I’m using addChild(submit_button);

  • edit – all the code is in one class file. i set the submit button at the start, – private var submit_button:SimpleButton; i have a function private function submitButton():void {
    submit_button=new SimpleButton();
    submit_button.x=200;
    submit_button.y=200;

        submit_button.upState=buttonShape();
        submit_button.overState=buttonShape();
        submit_button.downState=buttonShape();
    
    } and the drawing function seen above. and i add it to the stage in another function  - private function gameOver():void {
    
        addChild(submit_button);
        addChild(gameOver1);      basically this function is called on a hit test. and i have a text box that appears (this works) but when i add the button i get the error
    
  • 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-21T05:35:41+00:00Added an answer on May 21, 2026 at 5:35 am

    The function buttonShape() isn’t returning anything. Your inital line var rectangle:Shape = new Shape; is creating a local variable, which goes out of scope and ceases to exist at the end of the function.

    As buttonShape() doesn’t return anything, it’s actual function signature is:

    private function buttShape():void {}
    

    with a return void; being implied at the end of the function.

    This means that your code

    submit_button.upState=buttonShape();
    

    is essentially compiling to:

    submit_button.upState=null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a perfectly circular button, So I created a template from
Below is sample code to create a radio button element with Yes/No options in
I'm using my code-behind page to create a save button programmatically: Button btnSave =
I'm currently trying to hide a dynamically created table row after a button has
How do I create a button control (with CreateWindow of a BUTTON window class)
I need to create a button that has the same style as ButtonSpec with
In WPF, ASP.NET, WinForms, I create a button, double-click on it and fill in
I create a new Button object but did not specify the command option upon
I want to create a toggle button in html using css. I want it
Is it possible to create a toggle button in C# WinForms? I know that

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.