Here contains the code for handling mouse events in papervision 3d using flash cs3..
Code contains explanations ..
// import the necessary files..
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
//dictionary objects holds objects as key
var planebycontainer:Dictionary=new Dictionary();
var container:MovieClip=new MovieClip();
container.x=stage.stageWidth*0.5;
container.y=stage.stageHeight*0.5;
addChild(container);
this.frameRate=40;
//creating scene basic for papervision; among multiple scenes Scene3D is basic one
var scene:Scene3D=new MovieScene3D(container);
//camera to see objects
var camera:Camera3D=new Camera3D();
//initial camera zoom is (0,0,0);
//to zoom object into scene..
camera.zoom=10;
//star making planes...
//create material-by attaching bitmap using BitmapAssetMaterial
var bam:BitmapAssetMaterial=new BitmapAssetMaterial("FlashIcon");
//by default material applied to one side of object(here plane);
bam.oneSide=false;
bam.smooth=true;
for (var i:int=0; i<5; i++) {
//new Plane(material,height, width,triangle num,triangle num)---triangle num to control quality
var p:Plane=new Plane(bam,150,75,2,2);
p.x=50*i;//gives value from -500 to 500
p.y=40;
p.z=40*i;
//p.y=Math.random()*1000-500;
//p.z=Math.random()*1000-500;
//p.x=500
p.rotationY=45;//rotate individual
//p.addEventListener(MouseEvent.CLICK,clicker);
scene.addChild(p);
var container2:Sprite = p.container;
//here we have container as key and plane as value later we retrive plane by using container
planebycontainer[container2]=p
container2.buttonMode = true;
//adding event listeners for mouse events
container2.addEventListener( MouseEvent.ROLL_OVER, doRollOver );
container2.addEventListener( MouseEvent.CLICK, clicker );
container2.addEventListener( MouseEvent.ROLL_OUT, doRollOut );
}
scene.renderCamera(camera);
this.addEventListener(Event.ENTER_FRAME,render);
function render(e:Event) {
//render places object in scene
scene.renderCamera(camera);
}
function doRollOver(evt:MouseEvent) {
var sprit:Sprite=evt.target as Sprite;
sprit.alpha = 0.5;
}
function doRollOut(evt:MouseEvent) {
var sprit:Sprite=evt.target as Sprite;
sprit.alpha = 1;
}
function clicker(evt:MouseEvent) {
//here we retrieve the plane which is clicked
var sprit:Sprite=evt.target as Sprite;
var p:Plane=planebycontainer[sprit]
trace(p)
}
Basic papervision example