In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

papervision3d light and a flatshadedcube with tweensy

second click on the cube doesn't seem to 
fire an event
why and how to fix?
tweensy is doing something?
// forked from mash's papervision3d light and a flatshadedcube
// forked from mash's papervision3d simple example (cube)

// second click on the cube doesn't seem to 
// fire an event
// why and how to fix?
// tweensy is doing something?

package {
    import flash.display.*;
    import flash.events.*;

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;

    import com.flashdynamix.motion.Tweensy;

    public class PV3D_01 extends Sprite {
        private var camera    :Camera3D;
        private var scene     :Scene3D;
        private var viewport  :Viewport3D;
        private var renderer  :BasicRenderEngine;

        private var cube      :Cube;

        public function PV3D_01() {
            camera   = new Camera3D();
            camera.x = 0;
            camera.y = 0;
            camera.z = -1000;
            
            scene    = new Scene3D();
            viewport = new Viewport3D( stage.stageWidth, stage.stageHeight, false, true );
            renderer = new BasicRenderEngine();
            addChild( viewport );

            var light:PointLight3D = new PointLight3D(false);
            light.x = 0;
            light.y = 0;
            light.z = -1000;

            var material :FlatShadeMaterial = new FlatShadeMaterial(light, 0xD7261C );
            material.interactive = true;

            var materials :MaterialsList = new MaterialsList( { all : material } );
            cube = new Cube( materials );
            cube.x = 0;
            cube.y = 0;
            cube.z = 0;
            cube.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, function(e :InteractiveScene3DEvent) :void {
                // this goes well
                //e.displayObject3D.scaleX *= 1.3;

                // this fails after a click
                Tweensy.to( cube, { scaleX: 1.3 });
            });
            scene.addChild( cube );

            addEventListener( Event.ENTER_FRAME, onEnterFrame );
        }

        public function onEnterFrame(e:Event): void {
            cube.rotationX += ( mouseX - stage.stageWidth /2 ) / 200;
            cube.rotationY += ( mouseY - stage.stageHeight/2 ) / 200;

            renderer.renderScene( scene, camera, viewport );
        }
    }
}