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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:20:45+00:00 2026-06-14T05:20:45+00:00

If there is a main class which uses class Chan, given two codes, for

  • 0

If there is a main class which uses class Chan, given two codes, for example

public class Chan extends Sprite
{

    public function Chan():void
    {
       this.graphics.beginFill(0x123456); 
       this.graphics.drawRect(100,100,30,30);
    }
}

And

public class Chan extends Sprite
{
    public static var rect:Sprite=new Sprite(); 
    public function Chan():void
    {
       rect.graphics.beginFill(0x123456); 
       rect.graphics.drawRect(100,100,30,30);
    }
}

Why does one seems to work, and the other doesn’t ?

  • 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-14T05:20:46+00:00Added an answer on June 14, 2026 at 5:20 am

    scope. In the first example, you are drawing on the sprite instance itself that is already on the stage. rect in your second example is static and belongs to the class. So although you are drawing in it, it is not visible… it’s only in memory. If you add one more line to the second example, it will also be visible.

    public class Chan extends Sprite
    {
        public static var rect:Sprite=new Sprite(); 
        public function Chan():void
        {
            rect.graphics.beginFill(0x123456); 
            rect.graphics.drawRect(100,100,30,30);
            this.addChild(rect);
        }
    }
    

    EDIT:

    I wanted to elaborate on this a bit. The fact that rect was a static var wasn’t the main problem. I mentioned it was static in my answer but didn’t want that to confuse you. The reason it doesn’t work is the scope where you were drawing wasn’t in view… it was simply a variable. so even if it said:

    public var rect:Sprite = new Sprite();
    

    It would not be visible until you called addChild(rect) to actually add it into view.

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

Sidebar

Related Questions

I'm having a templated function that uses a local class which is derived from
Is there a class that overwrites the .MainMenu_MenuItem class for the Main Menu? I
Is there any way I can run class files (i.e. with main as the
I am writing a custom Control class in C# for my main project. There're
I have a wx.Frame, in which there is a main wx.Panel with several widgets
I have a class API which has full code coverage and uses DI to
I have several files with code testing code (which uses a unittest class). Later
In the book Python in a Nutshell (2nd Edition) there is an example which
I'm working on a server program, which uses multithreading. The problem is, there are
I have a pretty complex class which extends System.Windows.Forms.UserControl . It's written in C++/CLI

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.