Auf dem Weg der schönen Dinge ist ein kleines Werkzeug entstanden,
das ich euch nicht vorenthalten möchte.
Manchmal hat man unsichtbare Elemente, dessen Position irgendwie nicht hinhaut
und man wünscht sich einen Zeiger der zeigt wo das Teil oder eine virtuelle Position denn nun eigentlich ist.
Pointer zeichnet ein Fadenkreutz mit Linie und Text
So geht's
ActionScript:
import Pointer;
// zeichnet einen Punkt auf pos 100,100 mit dem text "mein Punkt"
// die pos. angaben werden automatisch angehängt
var p:Pointer = new Pointer(100, 100, "mein Punkt");
// _x um 50px verschieben
p.move_x(50);
// _x um 10 Prozent von 100px verschieben
p.move_x(100, 100, 10);
// _x um 10 Promille von 100px verschieben
p.move_x(100, 1000, 10);
// noch'n Punkt
// wenn zwei auf der selben Pos. liegen, wird die Linie verlängert
var p2:Pointer = new Pointer(161, 100, "mein Punkt2");
// den ersten Punkt löschen
p.clear();
// alle Punkte löschen
Pointer.clearAll();
Und hier die Pointer Klasse:
ActionScript:
class Pointer{
private static var _points_:Array = new Array();
private var point:MovieClip;
private var info:String;
// constuctor -> create the Point
function Pointer(x:Number, y:Number, txt:String){
var fx:Number = 50;
var th:Number = 20;
info = txt;
var i;
// enlarge the line
for (i = 0; i < _points_.length; i++){
if(_points_[i]._x == x && _points_[i]._y == y) fx += th;
}
// create point
var d:Number = _root.getNextHighestDepth();
var mc:MovieClip = _root.createEmptyMovieClip("__point__" + d, d);
point = mc;
mc._x = x;
mc._y = y;
// create line
mc.lineStyle(0,0xffffff,100);
mc.moveTo(-5, -5);
mc.lineTo(fx, fx);
mc.lineStyle(0, 0x000000, 100);
mc.moveTo(-4, -5);
mc.lineTo(fx + 1, fx);
// create cross
var mcc:MovieClip = mc.createEmptyMovieClip("cross", 0);
mcc.lineStyle(0,0,100);
mcc.moveTo(-5, 0);
mcc.lineTo(6, 0);
mcc.lineStyle(0,0xffffff,100);
mcc.moveTo(-5, 1);
mcc.lineTo(6, 1);
mcc._rotation = -45;
// create text
txt += " _x:" + x + " _y:" + y
mc.createTextField("tf1", 1, fx, fx - (th / 2), 250, th);
mc.tf1.textColor = 0xffffff;
mc.tf1.autoSize = "left";
mc.tf1.text = txt;
mc.createTextField("tf2", 2, fx + 1,fx + 1 - (th / 2), 250, th);
mc.tf2.textColor = 0x000000;
mc.tf2.autoSize = "left";
mc.tf2.text = txt;
// register point
_points_.push(mc);
}
// remove all points
public static function clearAll(Void):Void{
var i:Number;
for (i = 0; i < _points_.length; i++) _points_[i].removeMovieClip();
}
// remove single point
public function clear(Void):Void{
point.removeMovieClip();
}
// move point._x "normal" or "by percent"
// normal: move_x(300);
// by percent-1-: move_x(300, 100, 10); // move 10 percent per 100 of 300 px
// by percent-2-: move_x(300, 255, 10); // move 10 percent per 255 of 300 px
// by percent-2-: move_x(300, 1000, 10); // move 10 percent per thousand of 300 px
public function move_x(move:Number, pMax:Number, p:Number):Void{
if(pMax == undefined || p == undefined){
point._x += move;
}else if(pMax != undefined && p != undefined){
point._x += move / pMax * p;
}
point.tf1.text = point.tf2.text = info + " _x:" + point._x + " _y:" + point._y;
}
// same as move_x but for y position
public function move_y(move:Number, pMax:Number, p:Number):void{
if(pMax == undefined || p == undefined){
point._y += move;
}else if(pMax != undefined && p != undefined){
point._y += move / pMax * p;
}
point.tf1.text = point.tf2.text = info + " _x:" + point._x + " _y:" + point._y;
}
}