/source/flash/src/Main.as

http://github.com/agross/netopenspace · ActionScript · 103 lines · 75 code · 21 blank · 7 comment · 9 complexity · 84d2cc854944692b5c104b88a7b92d5a MD5 · raw file

  1. package
  2. {
  3. import flash.display.LoaderInfo;
  4. import flash.display.Sprite;
  5. import flash.events.Event;
  6. import flash.system.System;
  7. import flash.external.ExternalInterface;
  8. import flash.events.MouseEvent;
  9. import flash.display.Loader;
  10. import flash.net.URLRequest;
  11. /**
  12. * ...
  13. * @author mhoyer
  14. */
  15. public class Main extends Sprite
  16. {
  17. private var containerWidth:Number;
  18. private var containerHeight:Number;
  19. public function Main():void
  20. {
  21. if (stage) init();
  22. else addEventListener(Event.ADDED_TO_STAGE, init);
  23. }
  24. private function init(e:Event = null):void
  25. {
  26. buttonMode = true;
  27. removeEventListener(Event.ADDED_TO_STAGE, init);
  28. addEventListener(MouseEvent.MOUSE_DOWN, copy);
  29. containerWidth = parseInt(getParameter("width", stage.width.toString()));
  30. containerHeight = parseInt(getParameter("height", stage.height.toString()));
  31. //trace("\n\ncontainer dimension: " + containerWidth + "x" + containerHeight);
  32. addChild(loadContent(getParameter("backgroundAsset", "nos-badge-125x125.png")));
  33. }
  34. private function getParameter(name:String, defaultValue:String = null):String
  35. {
  36. var result:String = loaderInfo.parameters[name];
  37. if (result == null)
  38. {
  39. return defaultValue;
  40. }
  41. return result;
  42. }
  43. private function copy(e:Event = null):void
  44. {
  45. var clipboardContent:String = getParameter("clipboard");
  46. if (clipboardContent != null)
  47. {
  48. System.setClipboard(clipboardContent);
  49. }
  50. else
  51. {
  52. System.setClipboard("No parameters set.");
  53. }
  54. executeCommand(getParameter("callback"));
  55. }
  56. private function executeCommand(callback:String) : Object
  57. {
  58. trace("callback: " + callback);
  59. if (ExternalInterface.available && callback != null)
  60. return ExternalInterface.call(
  61. "eval",
  62. callback
  63. );
  64. return null;
  65. }
  66. public function loadContent(url:String):Loader
  67. {
  68. var loader:Loader = new Loader();
  69. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_Completed);
  70. loader.load(new URLRequest(url));
  71. return loader;
  72. }
  73. private function loader_Completed(event:Event):void
  74. {
  75. var li:LoaderInfo = event.target as LoaderInfo;
  76. li.loader.x = (100 - containerWidth) / 2;
  77. li.loader.y = (100 - containerHeight) / 2;
  78. // trace("Loader: " + li.loader.x + ":" + li.loader.y + " (dim= " + li.loader.width + "x" + li.loader.height + ")");
  79. // trace(stage.width);
  80. }
  81. }
  82. }