Cube interactivity example and source:
http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=6&aid=125

<http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=6&aid=125>
D





On 21 March 2011 03:49, ElyDeLaCruz <[email protected]> wrote:

> Hello to all,
> I need help trying to make my box react to the mouse.  I've tried the
> code below in different setups (grids, grids within object container
> 3d etc. you name it) but
> no matter what I do I get no response from my box :(  Can anybody help
>
> package
> {
>        import away3d.containers.ObjectContainer3D;
>        import away3d.containers.View3D;
>        import away3d.core.base.Object3D;
>        import away3d.events.MouseEvent3D;
>        import away3d.lights.PointLight;
>        import away3d.materials.ColorMaterial;
>        import away3d.primitives.Cube;
>
>        //import com.greensock.TweenLite;
>
>        import flash.display.Sprite;
>        import flash.display.StageAlign;
>        import flash.display.StageScaleMode;
>        import flash.events.Event;
>        import flash.events.MouseEvent;
>
>        [SWF(width="1600", height="900", frameRate="60")]
>        public class MouseEventsTest extends Sprite
>        {
>                private var view:View3D;
>                private var box:Cube;
>                private var SW:Number;
>                private var SH:Number;
>
>                public function MouseEventsTest()
>                {
>                        stage.align = StageAlign.TOP_LEFT;
>                        stage.scaleMode = StageScaleMode.EXACT_FIT;
>                        addEventListener(Event.ADDED_TO_STAGE,
> onAddedToStage);
>                }
>
>                private function onAddedToStage(e:Event):void
>                {
>                        removeEventListener(Event.ADDED_TO_STAGE,
> onAddedToStage);
>                        SW = stage.stageWidth;
>                        SH = stage.stageHeight;
>                        init();
>                }
>
>                private function init():void
>                {
>                        var light1:PointLight, light2:PointLight,
>                                light3:PointLight;
>
>                        // View
>                        view = new View3D();
>                        addChild(view);
>                        view.width = SW;
>                        view.height = SH;
>                        view.backgroundColor = 0xfeadea;
>
>                        // Lights
>                        light1 = new PointLight();
>                        light2 = new PointLight();
>                        light3 = new PointLight();
>                        light1.color = light2.color =
>                                light3.color = 0xFFFF99;
>                        light1.diffuse = light2.diffuse =
>                                light3.diffuse = 100;
>
>                        // Lights positioning
>                        light1.x = SW/2;
>                        light2.x = SW - ((SW/3) * 2) ;
>                        light3.x = SW - (SW/3);
>                        light1.y = light2.y = light3.y = 600;
>                        light1.z = light2.z = light3.z = 600;
>
>                        // Add lights
>                        view.scene.addChild(light1);
>                        view.scene.addChild(light2);
>                        view.scene.addChild(light3);
>
>                        // Add box
>                        box = new Cube(new ColorMaterial(0xff0000), 300,
> 300, 300);
>                        box.mouseEnabled = true;
>                        view.scene.addChild(box);
>                        box.material.lights = [light1, light2, light3];
>                        box.addEventListener(MouseEvent3D.ROLL_OVER,
> onBoxRollOver);
>                        box.addEventListener(MouseEvent3D.ROLL_OUT,
> onBoxRollOut);
>
>                        // Add Render Loop
>                        addEventListener(Event.ENTER_FRAME, onEnterFrame);
>                        //addEventListener(Event.RESIZE, onResize);
>
>                }
>
>                private function onBoxRollOver(e:MouseEvent3D):void {
>                        var o:Cube = Cube(e.object);
>                        //TweenLite.to(o, 1, {scaleX: 3, scaleY: 3});
>                        o.scaleX = o.scaleY = o.scaleZ = 2;
>                }
>
>                private function onBoxRollOut(e:MouseEvent3D):void
>                {
>                        var o:Cube = Cube(e.object);
>                        //TweenLite.to(o, 1, {scaleX: 1, scaleY: 1});
>                        o.scaleX = o.scaleY = o.scaleZ = 1;
>                }
>
>                /*private function onResize(e:Event):void
>                {
>                        view.width = SW = stage.stageWidth;
>                        view.height = SH = stage.stageHeight;
>                }*/
>
>                private function onEnterFrame(e:Event):void {
>                        //box.rotationY += .5;
>                        view.render();
>                }
>
>        }
> }

Reply via email to