OnClickEvent@Papervision3D
やっと出来た。
♥0 |
Line 97 |
Modified 2011-09-14 17:33:58 |
MIT License
archived:2017-03-20 13:48:58
ActionScript3 source code
/**
* Copyright Nowloading_ ( http://wonderfl.net/user/Nowloading_ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jSCR
*/
package {
import org.papervision3d.materials.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import flash.events.*;
[SWF(backgroundColor = 0x000000)]
public class testmePV3D extends BasicView {
private var material:ColorMaterial = new ColorMaterial(0xff0000);
private var material2:ColorMaterial = new ColorMaterial(0xffff00);
private var plane:Plane = new Plane(material,200,200);
private var rad:int = 0;
private var rad2:int = 30;
private var m:mado;
private var ma:int = 0;
public function testmePV3D() {
//extends BasicViewでMouseEventを登録する設定
//viewportと仕様マテリアルのinteractiveをtrueにする
super(465,465,true,true);
material.interactive = true;
camera.x = 0;
camera.y = 500;
camera.z = -500;
init();
}
private function init():void{
material.doubleSided = true;
material2.doubleSided = true;
scene.addChild(plane);
plane.y = 200;
startRendering();
addEventListener(Event.ENTER_FRAME,oEF);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,oOC);
}
private function oMC(e:Event):void{
if(ma==1){
removeChild(m);
ma = 0;
}
}
private function oEF(e:Event):void{
camera.z = -500*Math.cos(rad*Math.PI/180);
camera.x = 500*Math.sin(rad*Math.PI/180);
rad += 3;
if(rad >= 360)
rad = 0;
}
private function oOC(e:Event):void{
plane.rotationY += 10;
var color:uint = Math.random()*0xffffff;
if(ma == 1){
removeChild(m);
ma = 0;
}
if(ma == 0){
m = new mado();
m.x = mouseX;
m.y = mouseY;
addChild(m);
m.spr2.addEventListener(MouseEvent.CLICK,oMC);
ma = 1;
}
}
}
}
import flash.display.Sprite;
import flash.events.*;
class mado extends Sprite{
public var spr1:Sprite;
public var spr2:Sprite;
public function mado(){
graphics.lineStyle(1,0xffffff);
graphics.beginFill(0xffffff);
graphics.drawRect(0,0,100,100);
graphics.endFill();
spr1 = new Sprite();
spr1.graphics.lineStyle(1,0);
spr1.graphics.beginFill(0xff9999);
spr1.graphics.drawRect(10,10,80,30);
spr1.graphics.endFill();
addChild(spr1);
spr1.buttonMode = true;
spr2 = new Sprite();
spr2.graphics.lineStyle(1,0);
spr2.graphics.beginFill(0x9999ff);
spr2.graphics.drawRect(10,50,80,30);
spr2.graphics.endFill();
addChild(spr2);
spr2.buttonMode = true;
spr1.addEventListener(MouseEvent.CLICK,oMC1);
spr2.addEventListener(MouseEvent.CLICK,oMC2);
}
private function oMC1(e:MouseEvent):void{
removeChild(spr1);
}
private function oMC2(e:MouseEvent):void{
removeChild(spr2);
}
}