[Papervision3D] Cube addEventListener

Carlson, Jonathan David jdcarlson at liberty.edu
Wed Jan 30 13:34:04 PST 2008


Alright guys...got the cube to the point of a hand cursor appearing over
the face that I want to be clickable...but when I click nothing
happens...I've seen this same problem on the list archives, but couldn't
find any solutions. Heres the code:

 

public class main extends Sprite

                {

                                //
___________________________________________________________________
Static

 

                                static public  var SCREEN_WIDTH  :int =
1024;

                                static public  var SCREEN_HEIGHT :int =
768;

 

                                //
___________________________________________________________________ 3D
vars

 

                                protected var container :Sprite;

                                protected var scene
:InteractiveScene3D;

                                protected var camera   :Camera3D;

                                protected var
ism:InteractiveSceneManager;

                                protected var cube:Cube;

 

 

                                //
___________________________________________________________________ main

 

                                public function main()

                                {

                                                init3D();

 

                                                createCube();

 

                                                this.addEventListener(
Event.ENTER_FRAME, loop );

                                }

 

 

                                //
___________________________________________________________________
Init3D

 

                                private function init3D():void

                                {

 

                                                container = new
InteractiveSprite();

                                                addChild(container);

                                                container.name =
"mainCont";

                                                container.x =
stage.stageWidth*.5;

                                                container.y =
stage.stageHeight*.5;

 

                                                // Create scene

                                                scene = new
InteractiveScene3D(container);

                                                ism =
scene.interactiveSceneManager;

 
ism.setInteractivityDefaults();

 

                                                // Create camera

                                                camera = new Camera3D();

                                                camera.z = -1000;

                                                camera.zoom = 1;

                                                camera.focus = 300;

                                }

 

 

                                //
___________________________________________________________________
Create Cube

 

                                private function createCube()

                                {

                                                // Attributes

                                                var size :Number = 1000;

                                                var quality :Number =
20;

                                                var
myfront:InteractiveMovieAssetMaterial = new
InteractiveMovieAssetMaterial("Front",true);

                                                myfront.animated = true;

                                                myfront.smooth = true;

                                                var
myback:InteractiveMovieAssetMaterial = new
InteractiveMovieAssetMaterial("Back",true);

                                                myback.animated = true;

                                                myback.smooth = true;

 
myfront.movie.addEventListener(MouseEvent.CLICK, handleMainClick);

 
myback.movie.addEventListener(MouseEvent.CLICK, handleBackClick);

                                                // Materials

                                                var
materials:MaterialsList = new MaterialsList(

                                                {

                                                //all:

                                                front:  myfront,

                                                back:   myback,

                                                right:  new
MovieAssetMaterial( "Side", true ),

                                                left:   new
MovieAssetMaterial( "Side", true ),

                                                top:    new
MovieAssetMaterial( "Side", true ),

                                                bottom: new
MovieAssetMaterial( "Side", true )

                                                } );

 

                                                // Create the cube.

                                                cube = new Cube(
materials, size, 20, size, quality, quality, quality);

                                                cube.rotationY = -180;

 

                                                scene.addChild( cube,
"Cube" );

                                }

 

                                protected function
handleMainClick(e:MouseEvent):void

                                {

trace("vMouse click from btn", e.currentTarget);

                                }

                                protected function
handleBackClick(e:MouseEvent):void

                                {

                                                trace("vMouse click from
btn", e.currentTarget);

                                }

                                //
___________________________________________________________________ Loop

 

                                private function loop(event:Event):void

                                {

                                                update3D();

                                }

 

 

                                private function update3D():void

                                {

                                                //cube.rotationY =
container.mouseX / 2;

                                                //cube.rotationX =
container.mouseY / 2;

                                                //cube.rotationY -= 2;

 

                                                // Render

                                                scene.renderCamera(
this.camera );

                                }

                } 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20080130/4d59efb6/attachment-0001.html 


More information about the Papervision3D mailing list