先看效果:
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();
}
}
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |