[Papervision3D] InteractiveScene3DEvent

ilteris kaplan ilteriskaplan at gmail.com
Wed Nov 14 08:51:56 PST 2007


yep did that. Should I be adding name to my planes?

Here is the full source code:
package {
	import caurina.transitions.Tweener;
	
	import flash.display.*;
	import flash.events.*;
	
	
	
	import org.papervision3d.cameras.*;
	import org.papervision3d.events.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.scenes.*;
	import org.papervision3d.utils.*;
	
	
	[SWF(backgroundColor="0xFFFFFF", frameRate="100")]
	
	
	public class PV3PlaneArray extends Sprite {
		private var planeArr:Array;
		private var _sprite:Sprite;
		private var _scene:MovieScene3D;
		private var _camera:Camera3D;
		
		private var pieceWidth:Number;
		private var pieceHeight:Number; 
		private var totalNumPieces:Number;
		
		private var mc:MovieClip;
		private var imageHolder:DisplayObject3D;
		
		public function PV3PlaneArray() {
			planeArr = new Array();
			init();
		}
		
		private function init():void {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			createPlaceHolderMcs();
			init3D();
			createPlanes();
			addEventListener(Event.ENTER_FRAME, loop, false, 0, true);		
		}

		private function createPlaceHolderMcs():void {
			mc = new MovieClip;
			mc.name = "mc";
			mc.graphics.beginFill( 0x000000, 100 );
			mc.graphics.drawRect(0, 0, 140, 140);
			mc.graphics.endFill();
		}

		private function init3D():void {
			_sprite = new Sprite();
			addChild(_sprite);
			_sprite.name = "mainCont";
			_scene =  new MovieScene3D(_sprite, true);
			_scene.container.buttonMode = true;
			
			imageHolder = _scene.addChild(new DisplayObject3D("imageHolder"));
			
			imageHolder.z = 250;
			
			_camera = new Camera3D();
		
			_camera.focus = 250;
			
			
		} 
		
		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;
			
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.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);
			}
			
			_sprite.x = stage.stageWidth*.5;
			_sprite.y = stage.stageHeight*.5;
			
		}
		
		
				
		
		
		private function onMouseClick(e:MouseEvent):void {
			trace(this);
 
		}
		
		
		private function loop(e:Event):void {
			_scene.renderCamera(_camera);
		}
		
	}
}



Lindquist wrote:
> 
> Did you replace Scene3D with MovieScene3D?
> 
> On 11/14/07, ilteris kaplan <ilteriskaplan at gmail.com> wrote:
>>
>> 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
>>
>>
>>
>> _______________________________________________
>> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/InteractiveScene3DEvent-tf4801536.html#a13751447
Sent from the Papervision3D mailing list archive at Nabble.com.




More information about the Papervision3D mailing list