Hey everyone. I am trying to do something that seems pretty simple. But, being fairly new to AS3.0, I must be missing something stupid. I have several 3D blocks that follow your mouse when you move. When you click on a box, it zooms in to one of them and I want to remove the mouse listener. Pretty simple, eh? Well, it’s not working. Can anyone take a look and see what I’m missing.
The offending line is at the bottom. I keep getting the error:
“1120: Access of undefined property onEnterFrame”
I’m guessing this is a scope issue and I’m just addressing it wrong but I’ve tried everything.
Thanks for your help!
public class ProMax extends Sprite
{
private var viewport: Viewport3D;
private var scene: Scene3D;
private var camera: Camera3D;
private var renderer: BasicRenderEngine;
private var picCube: PictureCube;
private var mat: BitmapFileMaterial;
private var matList: MaterialsList;
private var cubes: Array;
private var boxWidth: Number = 300;
private var boxHeight: Number = 500;
private var boxDepth: Number = 10;
public function ProMax():void
{
viewport = new Viewport3D(800, 600, false, true);
addChild(viewport);
scene = new Scene3D();
camera = new Camera3D();
renderer = new BasicRenderEngine();
camera.y = 200;
cubes = new Array();
AddCube(0, 0);
AddCube(-400, 600);
AddCube(-600, 300);
AddCube(400, 100);
AddCube(800, 250);
AddCube(1200, 400);
AddCube(-500, 600);
AddCube(-1100, 250);
AddCube(-1500, 600);
function onEnterFrame(e:Event):void
{
camera.x = mouseX - 400;
renderer.renderScene(scene, camera, viewport);
}
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function AddCube(nx:Number, ny:Number) {
var pCube:Cube;
var matFront:BitmapFileMaterial = new BitmapFileMaterial("xwingskin.jpg");
matFront.doubleSided = true;
matFront.interactive = true;
var matLeft:ColorMaterial = new ColorMaterial(0x222222);
matLeft.doubleSided = true;
var matRight:ColorMaterial = new ColorMaterial(0x444444);
matRight.doubleSided = true;
var matTop:ColorMaterial = new ColorMaterial(0x666666);
matTop.doubleSided = true;
var matBottom:ColorMaterial = new ColorMaterial(0x888888);
matBottom.doubleSided = true;
var matBack:ColorMaterial = new ColorMaterial(0xaaaaaa);
matBack.doubleSided = true;
matList = new MaterialsList();
matList.addMaterial(matBack, "front");
matList.addMaterial(matFront, "back");
matList.addMaterial(matLeft, "left");
matList.addMaterial(matRight, "right");
matList.addMaterial(matBottom, "bottom");
matList.addMaterial(matTop, "top");
pCube = new Cube(matList, boxWidth, boxDepth, boxHeight, 1, 1, 1);
pCube.x = nx;
pCube.z = ny;
scene.addChild(pCube);
cubes.push(pCube);
pCube.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onPress);
function onPress(e:InteractiveScene3DEvent):void
{
// THIS IS THE LINE THAT FAILS
stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
if (camera.z != -1000) {
Tweener.addTween(camera, {x: e.target.x, time: 2, transition:"easeInOutQuint" } );
Tweener.addTween(camera, {z: -1000, time: 2, transition:"easeInOutQuint" } );
} else {
Tweener.addTween(camera, {x: e.target.x, time: 2, transition:"easeInOutQuint" } );
Tweener.addTween(camera, {z: e.target.z - 200, time: 2, transition:"easeInOutQuint" } );
}
}
}
}