• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

AS3 papervision3D: How do I get my mouseEvents to target only one plane and not all

I have images loaded into my planes and rotation in an internal carousel.  I am able to add mouse events yet it appears that every plane instance is being effected by them.  How do go about focusing on each individual plane that is being interacted with?

As to say on my OBJECT_OVER function:  the trace appears for the total number of instances.
As to say on my OBJECT_OUT function:  the trace appears for the total number of instances.
As to say on my OBJECT_PRESS function:  the trace appears for the total number of instances.

I need the function to only affect the e.currentTarget

Thanks for all the input in advance!
package {
	import flash.events.Event;
	import br.com.stimuli.loading.BulkLoader;
	import br.com.stimuli.loading.BulkProgressEvent;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import gs.easing.Quint;
	import gs.TweenLite;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.Viewport3D;

	public class Main extends BasicView {
		protected var planes:Array=[];
		protected var images:Array=[];
		protected var numItems:Number;
		protected var currentItem:Number=3;
		protected var angle:Number=25;
		protected var rightBtn:Sprite;
		protected var leftBtn:Sprite;
		protected var xmlPath:String="xml/imageXML.xml";
		protected var bulkInstance:BulkLoader;
		private var carousel:DisplayObject3D=new DisplayObject3D  ;
		private var bitmapViewport:Viewport3D=new Viewport3D(940,300);

		public function Main():void {
			super(940, 300, true, true);

			addChild(bitmapViewport);
			bitmapViewport.interactive=true;
			loadXML();
		}

		//First load our XML
		protected function loadXML():void {
			bulkInstance=new BulkLoader("bulkInstance");
			bulkInstance.add(xmlPath);
			bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onXMLReady);
			bulkInstance.start();
		}

		//When our xml is ready parse and load our images
		protected function onXMLReady(evt:BulkProgressEvent):void {
			bulkInstance.removeEventListener(BulkProgressEvent.COMPLETE, onXMLReady);
			bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onImagesReady);

			var xml:XML=bulkInstance.getXML(xmlPath);
			var xmlList:XMLList=xml.image;

			for (var i:int = 0; i < xmlList.length(); i++) {
				var imagePath:String=String(xmlList[i]);
				bulkInstance.add(imagePath);
				images.push(imagePath);
			}
			numItems=images.length;
		}
		protected function onImagesReady(evt:BulkProgressEvent):void {
			init();
		}
		protected function init():void {
			createChildren();
			startRendering();
		}
		protected function createChildren():void {
			for (var i:int = 0; i < numItems; i++) {
				var mat:BitmapMaterial=new BitmapMaterial(bulkInstance.getBitmapData(images[i]));
				mat.interactive=true;
				mat.smooth=true;
				var plane:Plane=new Plane(mat,360,280);
				carousel.addChild(plane);
				plane.rotationY=360/numItems*i;
				plane.moveForward(900);
				planes.push(plane);

				plane.id=i;
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onPlaneOver);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onPlaneOut);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, onPlaneClick);
				scene.addChild(carousel);
				startRendering();
			}
			camera.zoom=80;
		}
		protected function onPlaneOver(evt:InteractiveScene3DEvent):void {
			currentItem=evt.target.id;
			for (var i:int = 0; i < planes.length; i++) {
				var plane:Plane=planes[i];
				trace("onPlaneOver");
			}
		}
		protected function onPlaneOut(evt:InteractiveScene3DEvent):void {
			currentItem=evt.target.id;
			for (var i:int = 0; i < planes.length; i++) {
				var plane:Plane=planes[i];
				trace("onPlaneOut");
			}
		}
		protected function onPlaneClick(evt:InteractiveScene3DEvent):void {
			currentItem=evt.target.id;
			for (var i:int = 0; i < planes.length; i++) {
				var plane:Plane=planes[i];
				trace("onPlaneClick");
			}
		}

		override protected function onRenderTick(event:Event=null):void {
			carousel.rotationY-=viewport.containerSprite.mouseX/100;
			renderer.renderScene(scene,camera,bitmapViewport);
		}
	}
}

Open in new window

0
cubical38
Asked:
cubical38
1 Solution
 
vindys80Commented:
Hi,

I am not so sure about my knowledge in Papervision3D. But I have a clarification on your question. You saying you getting trace as much planes which you created? But its because you doing a for loop and doing a trace.

for (var i:int = 0; i < planes.length; i++) {
                                var plane:Plane=planes[i];
                                trace("onPlaneClick");
                        }

Another small doubt. I think

var plane:Plane = event.target as Plane; should give Plane. So what you trying to do with the for loop?

Saw a sample on google. Check whether its useful for you.
http://boxny.com/upload/nmetric/src/com/flashmoto/gallery/Gallery.as

Thanks
Vinod
0
 
cubical38Author Commented:
Yea I forgot to take the loop off, but the evt.target worked great...  Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now