I've been trying to re-create a tutorial by hand as part of a learning
exercise, and I am running into some behavior I can't explain, maybe
someone here can help me understand it.
In the code below I create a Scene3D object (called rootView) and
assign a new scene to it.
When I add some objects to that scene and render it it looks fine (not
pretty yet, but it renders).
But when I create a second View3D (var view1:View3D), and assign the
same scene to that view, I get the exception shown below the code.
The exception only occurs when I assign the same scene to a second
view.
The exception seems to stem from the original view attempting to
access rootView.stage when getting the default clipping area (noted in
View3D.as:811), but it is finding rootView.state to be null.
But this only occurs if the scene is assigned to the second view. I
wouldn't naturally expect this to occur. Can someone possibly explain
the interaction of the View3D, Scene3D, and stage in this case?
Many thanks for your time!
David
public function MultipleViewsTest()
{
scene = new Scene3D(); //Set up the scene
scene.autoUpdate = false;
addSomeObjectsToScene(scene); //Adds some simple primitive
objects
to the scene
rootView = new View3D(); //This is the main view in
use
---> rootView.scene = scene; //[[[[[ remove this line and
everything renders fine!!! ]]]]]
var view1:View3D = new View3D(); //Just created for testing
view1.scene = scene; //This is the line that
causes the error,
it works when this is removed.
rootView.camera.position = new Number3D(0, 1000, 1000);
rootView.camera.lookAt( new Number3D(0, 0, 0) );
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addChild(rootView);
}
private function onEnterFrame(e:Event):void {
trace("Scene: " + scene);
scene.update();
rootView.render();
}
==============================================
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
at away3d.containers::View3D/updateScreenClipping()[C:\MyProjects
\Game Project\Flash\away3d_3_3_3\away3d\containers\View3D.as:811]
at away3d.cameras::Camera3D/update()[C:\MyProjects\Game Project\Flash
\away3d_3_3_3\away3d\cameras\Camera3D.as:303]
at away3d.containers::Scene3D/update()[C:\MyProjects\Game Project
\Flash\away3d_3_3_3\away3d\containers\Scene3D.as:172]
at MultipleViews/onEnterFrame()[C:\MyProjects\Game Project\Flash\temp
\BasicProject\src\MultipleViews.as:85]