forked from jinzhu/clippy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClippy.hx
75 lines (63 loc) · 2.72 KB
/
Clippy.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.external.ExternalInterface;
class Clippy {
// Main
static function main() {
var text:String = flash.Lib.current.loaderInfo.parameters.text;
var id:String = flash.Lib.current.loaderInfo.parameters.id;
var call:String = flash.Lib.current.loaderInfo.parameters.call;
var copied:String = flash.Lib.current.loaderInfo.parameters.copied;
var copyto:String = flash.Lib.current.loaderInfo.parameters.copyto;
var callBack:String = flash.Lib.current.loaderInfo.parameters.callBack;
if(copied == null) copied = "copied!";
if(copyto == null) copyto = "copy to clipboard";
if(callBack == null) callBack = "function(){}";
// label
var label:TextField = new TextField();
var format:TextFormat = new TextFormat("Arial", 10);
label.text = copyto;
label.setTextFormat(format);
label.textColor = 0x888888;
label.selectable = false;
label.x = 15;
label.visible = false;
flash.Lib.current.addChild(label);
flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
// button
var button:SimpleButton = new SimpleButton();
button.useHandCursor = true;
button.upState = flash.Lib.attach("button_up");
button.overState = flash.Lib.attach("button_over");
button.downState = flash.Lib.attach("button_down");
button.hitTestState = flash.Lib.attach("button_down");
button.addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
if (text != null) {
flash.system.System.setClipboard(text);
ExternalInterface.call(callBack, text);
} else if (id != null) {
flash.system.System.setClipboard(ExternalInterface.call("function(id) { var elem = document.getElementById(id); if(elem) { return(elem.value || elem.innerHTML) } else { alert('WARN: ' + id + ' Not found '); } }", id));
ExternalInterface.call(callBack, id);
} else {
flash.system.System.setClipboard(ExternalInterface.call(call));
ExternalInterface.call(callBack, call);
}
label.text = copied;
label.setTextFormat(format);
});
button.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
label.visible = true;
});
button.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent) {
label.visible = false;
label.text = copyto;
label.setTextFormat(format);
});
flash.Lib.current.addChild(button);
}
}