We help IT Professionals succeed at work.

papervision3d unable to use MouseEvents.CLICK ; MOUSE_DOWN & MOUSE_UP

Medium Priority
1,733 Views
Last Modified: 2013-12-21
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

Comment
Watch Question

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!

Author

Commented:
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).
http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/ActionScript/Q_24122261.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

Out of interest, have you even tried replacing MouseEvent.CLICK with InteractiveScene3DEvent.OBJECT_CLICK
?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
well, I was just about to... ;)

Author

Commented:
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!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.