[Papervision3D] InteractiveScene3DEvent

ilteris kaplan ilteriskaplan at gmail.com
Wed Nov 14 07:56:30 PST 2007


Hey John,

I was trying mouseEvents I Flex Builder threw me this error when I  
try to assign a mouseClick event on planes in my for loop:
TypeError: Error #1009: Cannot access a property or method of a null  
object reference.

Do I have to store them in an array and am I supposed to add the  
EventListener somewhere different?

Thanks!

Here is the code:
for(var i:Number = 0; i < totalNumPieces; i++) {
				var plane:Plane = new Plane(material,mc.width,mc.height, 3 ,3 );
				planeArr.push(plane);
				plane.container.addEventListener( MouseEvent.CLICK , onMouseClick );
				//plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,  
onPlaneClick, false,0,true);
				//plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,  
onPlaneRollOver, false,0,true);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,  
onPlaneRollOut, false,0,true);
				
				plane.x = tempX ;
				plane.y = tempY ;
				plane.extra = {xPos:plane.x, yPos:plane.y, zPos:plane.z, id:i};
				
				tempY = tempY + pieceHeight + 10;
				if (tempY >= 140*4) {
					tempY = 0;
					tempX = tempX + pieceWidth + 10;
				}
				
				imageHolder.addChild(plane);
			}


On Nov 13, 2007, at 8:18 PM, John Lindquist wrote:

> The alternative is using a "MovieScene3D" instead of Scene3D which  
> puts all of the DisplayObject3D into MovieClips. So you would add a  
> listener like so:
>
> plane.container.addEventListener( MouseEvent.CLICK , onMouseClick );
>
> private function onMouseClick( event:MouseEvent ):void
> {
>     //do whatever
> }
>
> On 11/13/07, ilteris kaplan < ilteriskaplan at gmail.com> wrote:
> Hello All,
>
> I am still trying to find my way through PV3D and I do have couple  
> of questions regarding Events. Basically I have created several  
> planes on the stage and I am trying to assign mouseEvents on them.  
> As far as I understood, I do have several options here. One could  
> be put an default flash events on the material movieclip, (thus ,I  
> couldn't figure out how to specify which one is pressed, if I apply  
> the same materials to multiple planes) the other and which I am  
> using right now is to use InteractiveScene3DEvent on the planes.  
> Here's the snippet I do have:
>
> private function createPlanes(): void {
> 			pieceWidth = 140;
> 			pieceHeight = 140;
> 			totalNumPieces = 12;
> 			 var tempX:Number = 0;
> 			var tempY:Number = 0;
>  			
>  			
> 	 		var material:MovieMaterial = new MovieMaterial(mc, true);
> 			material.smooth = true;
> 			material.interactive = true;
> 			material.animated = true;
> 			
>  			//material.movie.addEventListener(MouseEvent.CLICK,  
> handleBTNClick);
> 		 	
> 			 for(var i:Number = 0; i < totalNumPieces; i++) {
> 				 var plane:Plane = new Plane(material,mc.width,mc.height, 3 ,3 );
>  				plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK ,  
> onPlaneClick, false,0, true);
> 				plane.addEventListener (InteractiveScene3DEvent.OBJECT_OVER,  
> onPlaneRollOver, false ,0,true);
> 				plane.addEventListener (InteractiveScene3DEvent.OBJECT_OUT,  
> onPlaneRollOut, false ,0,true);
> 				
> 				plane.x = tempX ;
> 		 		plane.y = tempY ;
> 				plane.extra = {xPos:plane.x, yPos:plane.y, zPos:plane.z, id:i};
> 	 			
> 	 			tempY = tempY + pieceHeight + 10;
> 				 if (tempY >= 140*4) {
>  					 tempY = 0;
> 		 			tempX = tempX + pieceWidth + 10;
> 				}
> 		 		
> 		 		_scene.addChild(plane);
> 			}
> 			
>  		}
>
> 	 private function onPlaneClick(is3d:InteractiveScene3DEvent): void {
>  			var clickedPlane:Plane = is3d.target as Plane;
> 		 	var targetZ:Number = clickedPlane.extra.zPos * -1;
> 			 	Tweener.addTween(clickedPlane, {
> 					 z:100,
> 					 time:1,
> 					 transition:"easeoutelastic"
> 				});
> 		 }
>
>
>
> As you can see, I don't even have to save my planes in an array and  
> pass an argument id to keep track of which plane has been clicked  
> since InteractiveScene3DEvent does everything for me. This works  
> just fine, but this keeps me wondering two things:
> 1-Do flash events are faster than InteractiveScene3DEvents?
> 2-How would you go as an alternative way?
>
> thanks
> ilteris
>
>
>
>
>
> _______________________________________________
> Papervision3D mailing list
> Papervision3D at osflash.org
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>
>
> _______________________________________________
> Papervision3D mailing list
> Papervision3D at osflash.org
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20071114/3c5dc2bc/attachment-0001.html 


More information about the Papervision3D mailing list