Skip to content

Commit

Permalink
Start work on a more context aware clippy that doesn't require as man…
Browse files Browse the repository at this point in the history
…y variables passed around
  • Loading branch information
cehoffman committed Feb 23, 2010
1 parent fcd2ef6 commit 7e9167c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions Clippy.hx
Expand Up @@ -18,7 +18,6 @@ class Clippy extends SimpleButton {

var callBack:String;
var text:String;
var id:String;

public function new() {
super();
Expand All @@ -36,19 +35,30 @@ class Clippy extends SimpleButton {
function onAddedToStage(e:Event) {
onStageResize(null);

callBack = flash.Lib.current.stage.loaderInfo.parameters.callBack;
text = flash.Lib.current.stage.loaderInfo.parameters.text;
id = flash.Lib.current.stage.loaderInfo.parameters.id;

if(callBack == null) callBack = "function(){}";
var id:String = flash.Lib.current.stage.loaderInfo.parameters.id;
text = flash.Lib.current.stage.loaderInfo.parameters.text;

if (id != null) {
callBack = "function (event) {
var clippy = document.getElementById('" + id + "');
if (clippy != null && typeof clippy[event] === 'function') {
var clipboard = clippy[event].call(clippy);
if (event === 'onClick') {
return clipboard;
}
}
}";
} else {
callBack = "function () {}";
}

// Add hooks to for javascript to call
ExternalInterface.addCallback("enable", enable);
ExternalInterface.addCallback("disable", disable);

// Let javascript know we are ready for use
enable();
ExternalInterface.call(callBack, "loaded", id);
ExternalInterface.call(callBack, "onLoaded");
}

function onStageResize(e:Event) {
Expand Down Expand Up @@ -79,18 +89,17 @@ class Clippy extends SimpleButton {
case MouseEvent.CLICK:
if (text != null) {
System.setClipboard(text);
ExternalInterface.call(callBack, text, id);
} else {
System.setClipboard(ExternalInterface.call(callBack, "click", id));
System.setClipboard(ExternalInterface.call(callBack, "onClick"));
}
case MouseEvent.MOUSE_OVER:
ExternalInterface.call(callBack, "mouseenter", id);
ExternalInterface.call(callBack, "onMouseEnter");
case MouseEvent.MOUSE_OUT:
ExternalInterface.call(callBack, "mouseleave", id);
ExternalInterface.call(callBack, "onMouseLeave");
case MouseEvent.MOUSE_DOWN:
ExternalInterface.call(callBack, "mousedown", id);
ExternalInterface.call(callBack, "onMouseDown");
case MouseEvent.MOUSE_UP:
ExternalInterface.call(callBack, "mouseup", id);
ExternalInterface.call(callBack, "onMouseUp");
}
}
}
Binary file modified build/clippy.swf
Binary file not shown.

0 comments on commit 7e9167c

Please sign in to comment.