前回のデータにマウスイベントを付加してみます。
とりあえず、めちゃくちゃ簡易的なものとして
「クリックするごとに大きくなる」ようにしてみます。
サンプル
JavascriptをONにし、最新のFlashプレーヤーをインストールしてください。
ドキュメントクラス
package
{
import flash.display.BitmapData;
import flash.events.Event;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
public class Main extends BasicView
{
private var _plane:Plane;
public function Main():void
{
super(0, 0, true, true);
viewport.buttonMode = true;
var bmd:BitmapData=new Img(180,180)
var bm:BitmapMaterial = new BitmapMaterial(bmd);
bm.doubleSided = true;
bm.smooth = true;
bm.interactive = true;
_plane = new Plane(bm, 300, 300, 3, 3);
_plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
scene.addChild(_plane);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
startRendering();
}
private function enterFrameHandler(e:Event):void{
_plane.rotationX = stage.mouseY - stage.stageHeight * 0.5;
_plane.rotationY = stage.mouseX - stage.stageWidth * 0.5;
}
private function clickHandler(e:InteractiveScene3DEvent):void
{
_plane.scaleX *= 1.1;
_plane.scaleY *= 1.1;
}
}
}
15行目:オブジェクトにマウスオーバーしたときのカーソルを指マークにします。
viewport.buttonMode = true
20行目:マウスイベントを受け取るようします。
bm.interactive = true
22行目:イベントリスナーを付けます。 Papervision3D独自のイベントInteractiveScene3DEventでクリックを判断します。
_plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler)
重要なのはこの辺りかと。
関連記事
- 初めての『Papervision3D 2.0』:その1(Great Whiteのドキュメント)
- 初めての『Papervision3D 2.0』:その2(BasicView)
- 初めての『Papervision3D 2.0』:その3(テクスチャの貼り付け
- 初めての『Papervision3D 2.0』:その4(マウスの座標をオブジェクトの回転に)
- 初めての『Papervision3D 2.0』:その5(テクスチャ画像にスムージング)
- 初めての『Papervision3D 2.0』:その6(3Dオブジェクトにマウスイベントを付加)
- 初めての『Papervision3D 2.0』:その7(3Dオブジェクトのアルファを変更)
- 初めての『Papervision3D 2.0』:その8(Tweenerとの連携)

コメントする