先日の記事でfla, asを分離できています。
さらに新しくASファイルを加えましょう。
AS3なので、package{}内に書く必要があって
下のようになります。
package {
import flash.display.Sprite;
public class ColorSelector extends Sprite {
public function ColorSelector() {
graphics.lineStyle(10,0x00aa00);
graphics.drawCircle(200,200,180);
}
}
}
後はflaにむすびつけたメイン関数内でimportして宣言し、
addChildすればよいです。
結びつけたASファイルがMain.asとしたら
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TransformGestureEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
import ColorSelector;
public class Main extends Sprite
{
public var stagew:int;
public var stageh:int;
private var basicview:BasicView;
private var cube:Cube;
private var yaw:Number = 0;
public var colorSelector:ColorSelector;
public function Main()
{
this.addEventListener(Event.ADDED_TO_STAGE,onInit);
}
protected function onInit(event:Event):void
{
stagew = stage.stageWidth;
stageh = stage.stageHeight;
basicview = new BasicView(stagew,stageh);
addChild(basicview);
var material:ColorMaterial = new ColorMaterial(0x888888);
cube = new Cube(new MaterialsList({all : material}),300,300,300);
basicview.scene.addChild(cube);
if(Multitouch.supportsGestureEvents){
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM,onBasicViewZoom);
stage.addEventListener(TransformGestureEvent.GESTURE_ROTATE,onBasicViewRotate);
}
basicview.startRendering();
colorSelector = new ColorSelector();
addChild(colorSelector);
}
protected function onBasicViewZoom(event:TransformGestureEvent):void
{
cube.scale *= event.scaleX;
}
protected function onBasicViewRotate(event:TransformGestureEvent):void
{
yaw += (event.rotation)/20;
cube.yaw(yaw);
}
}
}
papervision3dのコードがほとんどですが、
見るべきところはColorSelectorの部分です。
import, new, addChildすると表示されます。