Can't access the stage from my view

Almog's Avatar


05 Sep, 2010 09:51 PM

Hi I know I'm doing something wrong and I bet it's something simple but I can't access my stage from my view

This is my code and I keep getting a null error
this.viewport3D = new Viewport3D(this.stage.stageWidth, this.stage.stageHeight);

Here is the hole class

 * Constructor
public class Scene3DView extends Sprite

    public var flarManagerView:FlarMangerView;

    private var scene3D:Scene3D;
    private var viewport3D:Viewport3D;
    private var camera3D:FLARCamera_PV3D;
    private var renderEngine:LazyRenderEngine;
    private var pointLight3D:PointLight3D;

    public function Scene3DView()

        this.scene3D = new Scene3D();
        this.viewport3D = new Viewport3D(this.stage.stageWidth, this.stage.stageHeight);

        this.camera3D = new FLARCamera_PV3D(flarManagerView.flarManager, new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight));

        this.renderEngine = new LazyRenderEngine(this.scene3D, this.camera3D, this.viewport3D);

        this.pointLight3D = new PointLight3D();
        this.pointLight3D.x = 1000;
        this.pointLight3D.y = 1000;
        this.pointLight3D.z = -1000;

        //this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);

  1. 1 Posted by ZackPierce on 06 Sep, 2010 04:15 AM

    ZackPierce's Avatar

    The "stage" property of a DisplayObject is null until the DisplayObject is added to the display list (the tree of view components of which the stage is the root).

    So, if a view class needs to do stuff related to the stage, either don't do that stuff in the constructor and instead do it after the ADDED_TO_STAGE event has fired, or otherwise pass in the necessary data as constructor parameters. In this particular example, it seems that simply passing in two Numbers for the desired width and height should suffice.

  2. 2 Posted by Almog on 06 Sep, 2010 04:24 AM

    Almog's Avatar

    It has noting to do with stage not being added the first thing that I tried is using the ADDED_TO_STAGE event.

    I believe it has something to do with RobotLegs.

    I add the numbers as a temporary fix however this isn't a really good solution as it hard codes global values into a class.

  3. 3 Posted by Almog on 06 Sep, 2010 04:26 AM

    Almog's Avatar

    never mind I just re tried using the ADDED_TO_STAGE event, I got a different error and thought it was the same as stage error

  4. 4 Posted by Almog on 06 Sep, 2010 04:45 AM

    Almog's Avatar


  5. Almog closed this discussion on 06 Sep, 2010 04:45 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac