flash on 2014-4-1
♥0 |
Line 44 |
Modified 2014-04-01 18:44:41 |
MIT License
archived:2017-03-30 02:41:39
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bX9O
*/
package {
import flash.display.*;
import flash.events.*;
public class FlashTest extends Sprite {
private var s1:Sprite = new Sprite();
private var s2:Sprite = new Sprite();
public function FlashTest() {
// write as3 code here..
addEventListener(Event.ENTER_FRAME,onFrame);
s1.graphics.beginFill(0xff0000);
s1.graphics.drawRect(0,0,50,50);
s1.graphics.endFill();
addChild(s1);
s2.x = 200;
s2.y = 200;
s2.graphics.beginFill(0x0000ff);
s2.graphics.drawRect(0,0,50,50);
s2.graphics.endFill();
addChild(s2);
}
private function onFrame(e:Event):void{
s1.x = mouseX-s1.width/2;
s1.y = mouseY-s1.height/2;
//s1の中心座標
var s1cx:Number = s1.x+(s1.width/2);
var s1cy:Number = s1.y+(s1.height/2);
//s2の中心座標
var s2cx:Number = s2.x+(s2.width/2);
var s2cy:Number = s2.y+(s2.height/2);
//差
var disX:Number = s2cx - s1cx;
var disY:Number = s2cy - s1cy;
this.graphics.clear();
if(Math.abs(disX) <= (s1.width+s2.width)/2)this.graphics.lineStyle(1,0xff0000);
else this.graphics.lineStyle(1,0x00ff00);
this.graphics.moveTo(s1cx,100);
this.graphics.lineTo(s2cx,100);
this.graphics.moveTo(s1cx,100-10);
this.graphics.lineTo(s1cx,100+10);
this.graphics.moveTo(s2cx,100-10);
this.graphics.lineTo(s2cx,100+10);
this.graphics.moveTo(s2.x,100+10);
this.graphics.lineTo(s2.x+s2.width,100+10);
this.graphics.moveTo(s1.x,100+10);
this.graphics.lineTo(s1.x+s1.width,100+10);
}
}
}