tezzutezzu
July 8th, 2007, 01:12 PM
Hellow there...
still playing around with AS3. I'm working on having a camera panning and rotating in a 3d enviroment.
I wrote one class for the 3dStage mc present on the main fla and another for the 3d objects I'm attaching. I got stuck on this error:
Error #1009: Cannot access a property or method of a null object reference.
which happens when I try to push a new created 3dObject in the array of the objects of the scene.
Here's the code.
main fla:
import flash.events.Event;
stage3d.focalLength= 500;
var objectsInScene:Array;
var angleStep = 2*Math.PI/8;
for (var i=0; i<1; i++) {
var newObject:Object3d = new Object3d();
newObject.spin = 0;
newObject.angle = angleStep*i;
newObject.radius = 100;
newObject.x = Math.cos(newObject.angle)*newObject.radius;
newObject.z = Math.sin(newObject.angle)*newObject.radius;
newObject.y = stage3d.y-100;
newObject.addEventListener(Event.ADDED, stage3d.objectAdded);
objectsInScene.push(newObject);
addChild(newObject);
}
Stage3d.as :
package {
import flash.display.MovieClip;
import flash.events.Event;
import Object3d;
public class Stage3d extends MovieClip {
/*
* Instantiates a 3d stage
*/
public var z:Number;
public var focalLength:Number;
public function Stage3d() {
}
public function objectAdded(event:Event) {
trace(event.target);
displayObject(event.target);
}
private function displayObject(object3d:Object) {
trace(object3d);
var angle= object3d.angle + object3d.spin;
var x3d = Math.cos(angle)*object3d.radius;
var y3d = Math.sin(angle)*object3d.radius;
var y3d = object3d.y;
var scaleRatio = focalLength/(focalLength+z);
x = x3d *scaleRatio;
y = y3d *scaleRatio;
scaleY = object3d.scaleY = 100*scaleRatio;
scaleX = Math.sin(angle);
}
private function CreateCamera(xP, yP, rt) {
var x:Number = xP;
var y:Number = yP;
var rotation:Number = rt;
}
}
}
Object3d.as :
package {
import flash.display.MovieClip;
/*
* Define a 3d Object
*/
public class Object3d extends MovieClip {
public var z:Number;
public var angle:Number;
public var radius:Number;
public var spin:Number;
public function Object3d() {
}
}
}
Many of you will probably find some similarties with the 3d Senocular tutorial for AS2. Well, guess what?
It IS the 3d Senocular tutorial!!
aha very funny. ehm.
still playing around with AS3. I'm working on having a camera panning and rotating in a 3d enviroment.
I wrote one class for the 3dStage mc present on the main fla and another for the 3d objects I'm attaching. I got stuck on this error:
Error #1009: Cannot access a property or method of a null object reference.
which happens when I try to push a new created 3dObject in the array of the objects of the scene.
Here's the code.
main fla:
import flash.events.Event;
stage3d.focalLength= 500;
var objectsInScene:Array;
var angleStep = 2*Math.PI/8;
for (var i=0; i<1; i++) {
var newObject:Object3d = new Object3d();
newObject.spin = 0;
newObject.angle = angleStep*i;
newObject.radius = 100;
newObject.x = Math.cos(newObject.angle)*newObject.radius;
newObject.z = Math.sin(newObject.angle)*newObject.radius;
newObject.y = stage3d.y-100;
newObject.addEventListener(Event.ADDED, stage3d.objectAdded);
objectsInScene.push(newObject);
addChild(newObject);
}
Stage3d.as :
package {
import flash.display.MovieClip;
import flash.events.Event;
import Object3d;
public class Stage3d extends MovieClip {
/*
* Instantiates a 3d stage
*/
public var z:Number;
public var focalLength:Number;
public function Stage3d() {
}
public function objectAdded(event:Event) {
trace(event.target);
displayObject(event.target);
}
private function displayObject(object3d:Object) {
trace(object3d);
var angle= object3d.angle + object3d.spin;
var x3d = Math.cos(angle)*object3d.radius;
var y3d = Math.sin(angle)*object3d.radius;
var y3d = object3d.y;
var scaleRatio = focalLength/(focalLength+z);
x = x3d *scaleRatio;
y = y3d *scaleRatio;
scaleY = object3d.scaleY = 100*scaleRatio;
scaleX = Math.sin(angle);
}
private function CreateCamera(xP, yP, rt) {
var x:Number = xP;
var y:Number = yP;
var rotation:Number = rt;
}
}
}
Object3d.as :
package {
import flash.display.MovieClip;
/*
* Define a 3d Object
*/
public class Object3d extends MovieClip {
public var z:Number;
public var angle:Number;
public var radius:Number;
public var spin:Number;
public function Object3d() {
}
}
}
Many of you will probably find some similarties with the 3d Senocular tutorial for AS2. Well, guess what?
It IS the 3d Senocular tutorial!!
aha very funny. ehm.