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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:23:43+00:00 2026-05-12T09:23:43+00:00

I have the following two classes: package { import flash.display.Sprite; import flash.events.Event; public class

  • 0

I have the following two classes:

package 
{
    import flash.display.Sprite;
    import flash.events.Event;

    public class Main extends Sprite
    {

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {   
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            var test:NewClass = new NewClass(); 
        }

    }

}

AND

package  
{
    import flash.display.Sprite;

    public class NewClass extends Sprite
    {

        public function NewClass() 
        {
            trace(stage.width);
        }

    }

}

I get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at NewClass()[C:\Documents and Settings\Roma\poo\src\NewClass.as:10]
at Main/init()[C:\Documents and Settings\Roma\poo\src\Main.as:23]
at Main()[C:\Documents and Settings\Roma\poo\src\Main.as:15]

Why???

  • 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-12T09:23:43+00:00Added an answer on May 12, 2026 at 9:23 am

    yeah, a flash develop user … 😀

    uhm, the reason is: the stage is only available to objects, that are on the display list …

    modify your class as follows:

    package {
        import flash.display.Sprite;
        import flash.events.Event;
        public class NewClass extends Sprite {
            public function NewClass():void {
                    if (stage) init();
                    else addEventListener(Event.ADDED_TO_STAGE, init);
            }
            private function init(e:Event = null):void {       
                    removeEventListener(Event.ADDED_TO_STAGE, init);
                    trace(stage.width);//you may want to use stage.stageWidth actually
            }
        }
    }
    

    and Main::init as follows:

        private function init(e:Event = null):void {       
                removeEventListener(Event.ADDED_TO_STAGE, init);
                var test:NewClass = new NewClass();     
                this.addChild(test);
        }
    

    oh, and you can change your Coding Style Type from BraceAfterLine to BraceOnLine in Tools > Program Settings > FlashDevelop > Indenting, just in case you are inclined … 😉


    edit:
    if you want to access the stage, within the scope of a DisplayObject, you need to be sure, the stage is available to it … if you want to access the stage as soon as possible, then you will need the trick provided … but if you access the stage within a click handler for example, this automatically implies the DisplayObject is on the display list … it couldn’t be clicked otherwise …

    a little note though: i don’t think, it’s particularly clever to access the stage from everywhere … when it comes to display, your app hierarchy should follow the display list hierarchy, i.e. access goes from the root down the branches, and not the other way round … this is important to achieve reusability …


    greetz

    back2dos

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

Sidebar

Ask A Question

Stats

  • Questions 286k
  • Answers 286k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do this by splitting this value between two… May 13, 2026 at 4:56 pm
  • Editorial Team
    Editorial Team added an answer Relative links are calculated based on the value of the… May 13, 2026 at 4:56 pm
  • Editorial Team
    Editorial Team added an answer In Ruby 1.8, block arguments and method arguments have different… May 13, 2026 at 4:56 pm

Related Questions

Ok I've read an searched all over the web, and I've not found the
We have a Delphi 5 application, that is built without runtime packages, dlls or
I have the following two classes: TcmTPDataPanel = class(TcmTPBasePanel) Database: TnxDatabase; Session: TnxSession; private
Suppose I have the following two classes in two different assemblies: //in assembly A

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.