こんにちは、私の as3 に単純なボタンを実装しようとしています。しかし、これは機能していません。
シーンに bouton1 を追加しましたが、クリックしても何も起こりません (トレース機能にメッセージが表示されません)
これは私のコードです
package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.display.SimpleButton;
//import org.papervision3d.core.animation.clip.AnimationClip3D;
import org.papervision3d.objects.parsers.DAE;
//import org.papervision3d.objects.parsers.Max3DS;
//import org.papervision3d.objects.parsers.KMZ;
import org.papervision3d.view.BasicView;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.view.BasicView;
//added color to objects
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.core.math.Matrix3D;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.lights.PointLight3D;
public class ExternalModelsExample extends BasicView
{
private static const FORWARD:Number3D = new Number3D(0, 0, 1);
private var model:DisplayObject3D;
private var model2:DisplayObject3D;
private var model3:DisplayObject3D;/*
private var model4:DisplayObject3D;
private var model5:DisplayObject3D;
private var model6:DisplayObject3D;
private var model7:DisplayObject3D;
private var model8:DisplayObject3D;
private var model9:DisplayObject3D;
private var model10:DisplayObject3D;*/
private var rotX:Number = 0.2;
private var rotY:Number = 0.2;
private var camPitch:Number = 90;
private var camYaw:Number = 270;
private var easeOut:Number = 0.1;
// definition de la propriété couleur
private var color:ColorMaterial;
private var color2:ColorMaterial;
private var color3:ColorMaterial;/*
private var color4:ColorMaterial;
private var color5:ColorMaterial;
private var color6:ColorMaterial;
private var color7:ColorMaterial;
private var color8:ColorMaterial;
private var color9:ColorMaterial;
private var color10:ColorMaterial;*/
private var previousMousePoint:Point = new Point();
private var isMouseDown:Boolean = false;
var bouton1:SimpleButton = new SimpleButton();
public function ExternalModelsExample()
{
stage.frameRate = 40;
init();
startRendering();
addChild(bouton1);
bouton1.addEventListener(MouseEvent.CLICK, test);
stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler);
}
public function test(){
trace("test");
}
private function init():void
{
//Declaration color material
color = new ColorMaterial(0x65b5ff);
color2 = new ColorMaterial(0xffffff);
color3 = new ColorMaterial(0x757575);/*
color4 = new ColorMaterial(0x65b5ff);
color5 = new ColorMaterial(0xffffff);
color6 = new ColorMaterial(0x874630);
color7 = new ColorMaterial(0xbe0da7);
color8 = new ColorMaterial(0x3107bb);
color9 = new ColorMaterial(0xff4448);
color10 = new ColorMaterial(0xc7c7c7);*/
//COLLADA Utah Teapot
//Add import on top: import org.papervision3d.objects.parsers.DAE;
model = new DAE();
model.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model).load("assets/Z1.DAE", new MaterialsList ( { all:color } ));
model2 = new DAE();
model2.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model2).load("assets/Z2.DAE", new MaterialsList ( { all:color2 } ));
model3 = new DAE();
model3.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model3).load("assets/Z3.DAE", new MaterialsList ( { all:color3 } ));
/*model = new DAE();
model.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model).load("assets/Z4.DAE", new MaterialsList ( { all:color } ));
model2 = new DAE();
model2.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model2).load("assets/Z5.DAE", new MaterialsList ( { all:color2 } ));
model3 = new DAE();
model3.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model3).load("assets/Z6.DAE", new MaterialsList ( { all:color3 } ));
model = new DAE();
model.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model).load("assets/Z7.DAE", new MaterialsList ( { all:color } ));
model2 = new DAE();
model2.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model2).load("assets/Z9.DAE", new MaterialsList ( { all:color2 } ));
model3 = new DAE();
model3.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model3).load("assets/Z12-cockpit.DAE", new MaterialsList ( { all:color3 } ));
model = new DAE();
model.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
DAE(model).load("assets/Z13-barres.DAE", new MaterialsList ( { all:color } ));*/
}
private function modelLoaded(e:FileLoadEvent):void
{
scene.addChild(model);
scene.addChild(model2);
scene.addChild(model3);/*
scene.addChild(model4);
scene.addChild(model5);
scene.addChild(model6);
scene.addChild(model7);
scene.addChild(model8);
scene.addChild(model9);
scene.addChild(model10);*/
}
private function stage_mouseDownHandler(event:MouseEvent):void
{
isMouseDown = true;
}
private function stage_mouseUpHandler(event:MouseEvent):void
{
isMouseDown = false;
}
override protected function onRenderTick(e:Event=null):void
{
var currentMousePoint:Point = new Point(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY);
if(isMouseDown)
{
var difference:Point = currentMousePoint.subtract(previousMousePoint);
var vector:Number3D = new Number3D(difference.x, difference.y, 0);
var rotationAxis:Number3D = Number3D.cross(vector, FORWARD);
rotationAxis.normalize();
var distance:Number = Point.distance(currentMousePoint, previousMousePoint);
var rotationMatrix:Matrix3D = Matrix3D.rotationMatrix(rotationAxis.x, -rotationAxis.y, rotationAxis.z, distance/250);
model.transform.calculateMultiply3x3(rotationMatrix, model.transform);
model2.transform.calculateMultiply3x3(rotationMatrix, model2.transform);
model3.transform.calculateMultiply3x3(rotationMatrix, model2.transform);
}
previousMousePoint = currentMousePoint;
super.onRenderTick();
}
}
}
なぜ私の trace("test") が動かないのかわかりますか??
オブジェクトのドラッグと競合がありますか?
フラッシュにエラーが表示されない
ありがとう