Change shape to sprite for interative.

2011/4/1, Hupie <[email protected]>:
> Hey,
>
> I'm pretty new to away3d, actionscript and programming in general (I'm
> a 3d artist) so please keep that in mind. I want to make a simple HUD
> on top of a away3d scene but i cant get the event listeners to work on
> 2d shapes. The hud button should control the camera position as u can
> see in the code below. For the button i used a simple circle shape and
> added an event listener to it but unfortunately my method doesn't
> work.
>
> How can i get hud buttons to work (make clickable) in away3d?
>
>
> package
> {
>       import away3d.cameras.Camera3D;
>       import away3d.cameras.TargetCamera3D;
>       import away3d.containers.ObjectContainer3D;
>       import away3d.containers.View3D;
>       import away3d.primitives.Cube;
>       import flash.display.MovieClip;
>       import flash.display.Shape;
>       import flash.display.SimpleButton;
>       import flash.display.Sprite;
>       import flash.events.Event;
>       import flash.events.KeyboardEvent;
>       import flash.events.MouseEvent;
>       import flash.geom.Vector3D;
>
>       import com.greensock.TweenLite;
>
>
>       [SWF(width = "500", height = "400", frameRate = "60", backgroundColor
> = "#FFFFFF")]
>
>       public class Main extends Sprite
>       {
>
>               private var cam:TargetCamera3D;
>               private var View:View3D;
>               private var cube:Cube;
>               private var cam_dummy:Cube;
>               private var currentview:uint = 1;
>
>               private var plek3:Vector3D = new Vector3D( -600, -300, 800);
>               private var plek2:Vector3D = new Vector3D( -100, 600, 500);
>               private var plek1:Vector3D = new Vector3D(300, 300, 300);
>
>               private var button:SimpleButton;
>               private var shape:Shape;
>
>               private var switchcam:Boolean = new Boolean(false);
>
>               public function Main():void
>               {
>
>                       // create a basic camera
>                       cam = new TargetCamera3D();
>                       cam.position = plek1;
>
>                       // create a viewport
>                       View = new View3D({camera:cam, x:250,y:200});
>                       addChild(View);
>
>                       cube= new Cube();
>                       View.scene.addChild(cube);
>
>                       cam_dummy = new Cube();
>                       View.scene.addChild(cam_dummy);
>                       cam_dummy.position = plek1;
>                       cam_dummy.visible = false;
>
>                       stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
>                       //stage.addEventListener(KeyboardEvent.KEY_DOWN, 
> nextview);
>
>
>                       //create button
>                       button = new SimpleButton();
>                       addChild(button);
>                       button.x = 50;
>                       button.y = 50;
>
>                       //create overlay item
>                       shape = new Shape();
>                       shape.graphics.beginFill(0x000000, 1);
>                       shape.graphics.drawCircle(50, 50, 25);
>                       //shape.graphics.endFill();
>                       addChild(shape);
>
>
>                       stage.addEventListener(MouseEvent.MOUSE_DOWN, nextview);
>
>               }
>
>               public function nextview (e:MouseEvent):void
>               {
>                       trace(e.target);
>                       if (e.target == shape){
>                               switchcam = true;
>                               if (currentview == 3) currentview = 1
>                               else currentview ++;
>                               trace(currentview);
>
>                               if(currentview == 1)
>                               TweenLite.to(cam, 1, { x:plek1.x, y:plek1.y, 
> z:plek1.z } );
>                               else if(currentview == 2)
>                               TweenLite.to(cam, 1, { x:plek2.x, y:plek2.y, 
> z:plek2.z } );
>                               else if(currentview == 3)
>                               TweenLite.to(cam, 1, { x:plek3.x, y:plek3.y, 
> z:plek3.z } );
>                       }
>               }
>
>               public function onEnterFrame(e:Event):void
>               {
>                       View.render();
>
>
>
>
>               }
>
>       }
>
> }

Reply via email to