Hi guys,
I really hope someone can help me. I am trying to animate a few primitives that have been created dynamically with tweener. It works if the tweener method is inside the loop, but not when it is outside. Please could anyone point me in the right direction. here is my code:
package
{
import flash.display.*;
import flash.events.*;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.lights.PointLight3D;
import caurina.transitions.*;
public class Menu3D extends Sprite
{
private var vPort : Viewport3D;
private var dObject : DisplayObject3D;
private var scene : Scene3D;
private var camera : Camera3D;
private var mat : ColorMaterial;
private var gouraud : GouraudMaterial;
private var bmp : BitmapFileMaterial;
private var bmp2 : BitmapFileMaterial;
private var bmp3 : BitmapFileMaterial;
private var bmp4 : BitmapFileMaterial;
private var matList : MaterialsList
private var plane : Plane;
private var plane2 : Plane;
private var render : BasicRenderEngine;
private var pointLight: PointLight3D;
private var spacing : Number = 280;
private var clipCount: Number = 0;
private var cubeArray: Array = [];
private var bmpArray : Array = [];
public function Menu3D():void
{
init();
}
public function init():void
{
//vPort = new ViewPort3D(width,height,scaleToStage:Boolean,interactive:Boolean);
vPort = new Viewport3D(955,600,true,true);
addChild(vPort);
//instantiate scene3d
scene = new Scene3D();
scene.addChild(dObject);
//instantiate new camera
camera = new Camera3D();
camera.zoom = 14;
camera.x = 450;
camera.focus = 40;
//renderer draws the scene to the stage
render = new BasicRenderEngine();
//creates a new material
mat = new ColorMaterial(0x333333);
mat.doubleSided = true;
bmp = new BitmapFileMaterial("mImg1.jpg");
bmp.doubleSided = true;
bmp2 = new BitmapFileMaterial("mImg2.jpg");
bmp2.doubleSided = true;
bmp3 = new BitmapFileMaterial("mImg3.jpg");
bmp3.doubleSided = true;
bmp4 = new BitmapFileMaterial("mImg4.jpg");
bmp4.doubleSided = true;
bmpArray.push(bmp);
bmpArray.push(bmp2);
bmpArray.push(bmp3);
bmpArray.push(bmp4);
for (var i:int = 0; i<4; i++)
{
//plane = new Plane(material,w,h,wSegments,hSegments);
plane = new Plane(bmpArray*,200,200,2,2);
plane.z = Math.round(Math.random()*800);
plane.x = 20+spacing*i;
plane.name = "plane"+i;
dObject.addChild(plane);
cubeArray.push("plane"+i);
//trace(cubeArray);
//works if tweener is here
//Tweener.addTween(plane,{rotationY:-750,time:2});
test()
}
addEventListener(Event.ENTER_FRAME, doEnterFrame, false, 0, true);
}
public function test():void
{
trace(plane.name);
Tweener.addTween(getChildByName("plane"+0),{rotationY:-750,time:2});
}
public function doEnterFrame(evt:Event):void
{
render.renderScene(scene,camera,vPort);
}
}
}
Thank you.