複数のインスタンスに、同時に絵を描くアプリを作りたいおですが、どこがおかしいのか、わからないまま、つまずいてしまっています。どなたか、回答を、お願いします。
package {
import flash.display.Graphics; import flash.display.Sprite; import flash.display.Shape; import flash.events.MouseEvent; import flash.events.Event; import flash.geom.Point; public class draw_lines_001 extends Sprite { private static const INIT_SEGMENTS:uint=10; private static const THICKNESS:uint=5; private static const COLOR:uint=0xffcccc; private static const ALPHA:Number=0.1; private static const ROTATION_RATE:uint=1; private var _shapeHolder:Sprite; private var _shapes:Vector.<Shape>; public function draw_lines_001():void { init(); } public function init():void{ _shapeHolder=new Sprite(); _shapeHolder.x=50; _shapeHolder.y=50; addChild(_shapeHolder); for(var i:uint=0;i<INIT_SEGMENTS;i++){ addSegment(); } positionSegments(); stage.addEventListener(MouseEvent.MOUSE_DOWN,mouse_down); stage.addEventListener(MouseEvent.MOUSE_UP,mouse_up); } private function addSegment():void{ var shape:Shape=new Shape(); if(_shapes.length>0){ shape.graphics.copyFrom(_shapes[0].graphics); }else{ shape.graphics.lineStyle(THICKNESS,COLOR,ALPHA); } _shapes.push(shape); _shapeHolder.addChild(shape); }
// private function remooveSegment():void{
// var shape:Shape=_shapes.pop();
// _shapeHolder.removeChild(shape);
// }
private function positionSegments():void{ var segments:uint=_shapeHolder.numChildren; var angle:Number=360/segments; for(var i:uint=1;i<segments;i++){ _shapes[i].rotation=angle*i; } } private function mouse_down(event:MouseEvent):void{ var shape:Shape=_shapes[0]; shape.graphics.moveTo(shape.mouseX,shape.mouseY); addEventListener(Event.ENTER_FRAME,onThisEnterFrame); } private function mouse_up(event:MouseEvent):void{ removeEventListener(Event.ENTER_FRAME,onThisEnterFrame); } private function onThisEnterFrame(event:Event):void{ _shapeHolder.rotation+=ROTATION_RATE; draw(); } private function draw():void{ var shape:Shape=_shapes[0]; shape.graphics.lineTo(shape.mouseX,shape.mouseY); var segments:uint=_shapeHolder.numChildren; for(var i:uint=1;i<segments;i++){ _shapes[i].graphics.copyFrom(shape.graphics); } } }
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/29 17:28