Main:
package {
import as3.Mc;
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author ...
*/
public class Main extends Sprite {
private var line:Sprite;
private var mcs:Array=[];
public function Main():void {
line = new Sprite();
addChild(line);
init();
}
private function init() {
for (var i:uint = 0; i<4; i++) {
var mc = new Mc();
mc.x=20*Math.random()+20*i;
mc.y=20*Math.random()+20*i;
addChild(mc);
mcs.push(mc);
}
addEventListener(Event.ENTER_FRAME, f);
}
private function f(e:Event) {
line.graphics.clear();
line.graphics.lineStyle(1);
line.graphics.moveTo(mcs[0].x, mcs[0].y);
for (var i:uint =1; i <4; i++) {
line.graphics.lineTo(mcs[i].x,mcs[i].y);
}
line.graphics.lineTo(mcs[0].x,mcs[0].y);
}
}
}
Mc:
package as3
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author ...
*/
public class Mc extends Sprite
{
public function Mc():void {
addEventListener(MouseEvent.MOUSE_DOWN, d);
addEventListener(MouseEvent.MOUSE_UP, u);
}
private function d(e:MouseEvent):void{
e.currentTarget.startDrag();
}
private function u(e:MouseEvent):void {
e.currentTarget.stopDrag();
}
}
}