I solved it by using a Sprite for the shape variable instead of Shape. Seems like adding mouse-eventlisteners to Shapes doesn't work with Away3D (tried shape.addEventListener.. as well, but didn't work either).
On 1 apr, 19:37, Bob Warfield <[email protected]> wrote: > Hi. I wonder if your problem was related to mine. I do a lot of wireframe > graphics (Segments added to Meshes) with Away3D and was adding listeners to > stage. One thing I noticed is the mouse events just got eaten whenever I > pointed at any Away3D segment--the mouse hot spot had to over clear space. > > I never did figure out why this was. I know Fabrice mentioned he hadn't > seen the problem in his code. In the end, rather than keep fooling with it, > I added a transparent layer and catch the mouse events there. > > There's definitely something either wrong, or not quite intuitive on this > area though. > > Cheers, > > BW > > On Fri, Apr 1, 2011 at 9:38 AM, Josh Beckwith <[email protected]>wrote: > > > > > > > > > Have you tried adding a mouse event listener to the shape instead of > > the stage? > > > Also, if your UI is going to include more than a few buttons and > > graphics, I recommend using mxml. If you're unfamiliar with it, it > > won't take long to learn. It's pretty similar to html. > > > On Apr 1, 2:34 am, Hupie <[email protected]> wrote: > > > 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(); > > > > } > > > > } > > > > }
