I am making an interactive Flash site and recently installed Papervision. I thought it would be cool to have a spinning 3D cube (using Papervision imports and so on). Unfortunately when I click on the ‘Links’ page (the ‘links’ keyframe with the AS3 actions) the cube appears, but when I got back to other pages (for example Homepage) the cube is still there!!
I was wondering how I unload/remove/un-import/?? this so that it works ONLY on that one keyframe.
The code is as follows (I didn’t write this - it was copied):
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
addChild(viewport);
viewport.buttonMode = true;
var renderer:BasicRenderEngine = new BasicRenderEngine();
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 100;
var mam:MovieMaterial = new MovieMaterial(face);
mam.interactive = true;
mam.smooth = true;
mam.animated = true;
var mam2:MovieMaterial = new MovieMaterial(face2);
mam2.interactive = true;
mam2.smooth = true;
mam2.animated = true;
var mam3:MovieMaterial = new MovieMaterial(face3);
mam3.interactive = true;
mam3.smooth = true;
mam3.animated = true;
var mam4:MovieMaterial = new MovieMaterial(face4);
mam4.interactive = true;
mam4.smooth = true;
mam4.animated = true;
var mam5:MovieMaterial = new MovieMaterial(face5);
mam5.interactive = true;
mam5.smooth = true;
mam5.animated = true;
var mam6:MovieMaterial = new MovieMaterial(face6);
mam6.interactive = true;
mam6.smooth = true;
mam6.animated = true;
var cube:Cube = new Cube(new MaterialsList({front:mam, back:mam2, left:mam3, right:mam4,top:mam5, bottom:mam6}), 100, 100, 100, 10, 10, 10);
scene.addChild(cube);
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void
{
var xDist:Number = mouseX - stage.stageWidth * 0.5;
var yDist:Number = mouseY - stage.stageHeight * 0.5;
cube.rotationY += xDist * 0.05;
cube.rotationX += -yDist * 0.05;
renderer.renderScene(scene, camera, viewport);
}
face.addEventListener(MouseEvent.CLICK, faceClick);
function faceClick(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.napier.ac.uk"));
}
face2.addEventListener(MouseEvent.CLICK, face2Click);
function face2Click(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.nrc.ac.uk/"));
}
face3.addEventListener(MouseEvent.CLICK, face3Click);
function face3Click(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.flickr.com"));
}
face4.addEventListener(MouseEvent.CLICK, face4Click);
function face4Click(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.youtube.com"));
}
face5.addEventListener(MouseEvent.CLICK, face5Click);
function face5Click(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.facebook.com"));
}
face6.addEventListener(MouseEvent.CLICK, face6Click);
function face6Click(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.adobe.com"));
}
On the other keyframes, I have tried
scene.removeChild(cube);
- it removes the cube, but it disables buttons and other features from working giving an error
1009 Cannot access a property or method of a null object reference.
.
Someone told me I need to ‘null’ this to clean Flash’s memory of the 3D cube. Do you have any suggestions please? I’m pretty fixated on having this feature on my site, so it would be great if you could help.
Many thanks.