forked from: ローカル座標の取得
♥0 |
Line 47 |
Modified 2010-01-26 11:07:48 |
MIT License
archived:2017-03-20 15:11:20
ActionScript3 source code
/**
* Copyright hacker_yk666qry ( http://wonderfl.net/user/hacker_yk666qry )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xTUA
*/
// forked from kihon's ローカル座標の取得
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Main extends Sprite
{
private var canvas:Sprite;
private var globaltf:TextField;
private var localtf:TextField;
public function Main()
{
// 100 * 100ピクセルの青四角形
canvas = new Sprite();
canvas.graphics.beginFill(0x009AD6);
canvas.graphics.drawRect(0, 0, 100, 100);
canvas.graphics.endFill();
addChild(canvas);
// 青四角形の位置をずらしておく
canvas.x = canvas.y = 50;
globaltf = Text.createTextField("", 24, 0x0);
localtf = Text.createTextField("", 24, 0x0);
localtf.y = 380;
globaltf.y = 420;
addChild(globaltf);
addChild(localtf);
// マウスを動かしたときにイベントを呼び出す
canvas.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove(event:MouseEvent):void
{
localtf.text = "localX(" + event.localX + ") : localY(" + event.localY + ")"; // ローカル座標
globaltf.text = "globalX(" + mouseX + ") : globalY(" + mouseY + ")"; // グローバル座標
}
}
}
import flash.text.TextField;
import flash.text.TextFormat;
class Text
{
public static function createTextField(text:String, size:int, color:int):TextField
{
var tf:TextField = new TextField();
tf.defaultTextFormat = new TextFormat("_typeWriter", size, color, true);
tf.text = text;
tf.autoSize = "left";
tf.selectable = false;
return tf;
}
}