Link to home
Start Free TrialLog in
Avatar of Dreammonkey
DreammonkeyFlag for Belgium

asked on

papervision3d unable to use MouseEvents.CLICK ; MOUSE_DOWN & MOUSE_UP

I'm using code below to listen for mouseEvents on Planes in my papervision3d (v 2.0) scene.
The MOUSE_OVER and MOUSE_OUT Listeners seem to work;

The CLICK ; MOUSE_UP; MOUSE_DOWN don't work !

why could this be?
Thanks in advance,

DM
var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
addChild(viewport);
                        
var renderer:BasicRenderEngine = new BasicRenderEngine();
 
var scene:Scene3D = new Scene3D();
 
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 50;   
 
var terSize:uint=2;
var kwad:uint=terSize*terSize;
var row:uint=1;
var mam:MovieMaterial;
var cube:Plane;
var tile:earth;
var terArray:Array = new Array();
 
for (var i:uint=0; i<kwad; i++) {
	if (i==terSize*row) {
		row++;
	}
	terArray.push(new earth());
	tile = terArray[i];
		
	mam = new MovieMaterial(tile);
	mam.interactive = true;
	mam.smooth = true;
	mam.animated = true;
		
	cube = new Plane(mam);
	cube.name = "Tile "+i.toString();
	cube.x = (i-(terSize*(row-1)))*200;
	cube.y = 200*(row-1);
	
//THIS ONE WORKS
	cube.addEventListener(MouseEvent.MOUSE_OVER, onTileOver);
	function onTileOver(e:Event):void {
		trace(e.currentTarget.name);
	}
//THIS ONE DOESN'T ...
	cube.addEventListener(MouseEvent.CLICK, onTileClick);
	function onTileClick(e:Event):void {
		trace(e.currentTarget.name);
	}
 
	scene.addChild(cube);
}

Open in new window

Avatar of pepsichris
pepsichris
Flag of United Kingdom of Great Britain and Northern Ireland image

It's basically cos CLICK doesn't bubble in the same way a MOUSE_OVER/ROLL_OVER etc, and Papervision sets the scenario up slightly differently to how you expect, so you need to work around it.  There's a nice tutorial here:

http://papervision2.com/advanced-interactivity-2/

...which will show you the basis for the cleanest workaround.  Good luck!
Avatar of Dreammonkey

ASKER

Thanks for the tip !
Good to see there actually are tutorials on papervision out there !

The approach is a bit far fetched for me, I tried it but it's very heavy on the cpu ...
and not that reliable after all...

What's more I'm working with planes (a lot of them) what makes it even more complex...

I tried another backdoor (see snippet)

Any idea if one could extend the papervison3d class to enable these listeners after all?
I don't see why the mouse_over and mouse_out are supported and the others aren't...

PS: In my previous question we found that it wasn't a big deal to extend the class so it would allow the getChildAt method (not supported in papervision either).
https://www.experts-exchange.com/questions/24122261/Papervision3d-Scene3D-getChildAt-method-undefined.html 
cube.addEventListener(MouseEvent.MOUSE_OVER, onTileOver);
	cube.addEventListener(MouseEvent.MOUSE_OUT, onTileOut);
	
	function onTileOver(e:Event):void {
		//trace(e.currentTarget.name);
		lookFor =scene.getChildAt(e.currentTarget.inc);
		trace(lookFor.inc);
	}
	function onTileOut(e:Event):void {
		//trace(e.currentTarget.name);
		lookFor =null;
		trace(lookFor);
	}
holder.Tholder.addEventListener( MouseEvent.CLICK, onTileClick);
 
function onTileClick(e:MouseEvent) {
	if(lookFor != null) {
		trace( lookFor.name+" was CLICKED!!!");
	}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pepsichris
pepsichris
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
well, I was just about to... ;)
bloody marvellous !


cube.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onTileClick);
function onTileClick(e:InteractiveScene3DEvent) {
	var lookFor:*=scene.getChildAt(e.currentTarget.inc);
	trace( lookFor.name+" was CLICKED!!!");
}

Open in new window

Glad it worked out!