ExternalInterfaceManager.as 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package {
  2. import flash.external.ExternalInterface;
  3. /**
  4. * This manages all External calls, not all players have this ability (Flex does not,
  5. * flash in a browser does, flash standalone does not)
  6. *
  7. * We also have an optional chart_id that the user may set, this is passed out
  8. * as parameter one if it is set.
  9. */
  10. public class ExternalInterfaceManager
  11. {
  12. public var has_id:Boolean;
  13. public var chart_id:String;
  14. private static var _instance:ExternalInterfaceManager;
  15. public static function getInstance():ExternalInterfaceManager {
  16. if (_instance == null) {
  17. _instance = new ExternalInterfaceManager();
  18. }
  19. return _instance;
  20. }
  21. public function setUp(chart_id:String):void {
  22. this.has_id = true;
  23. this.chart_id = chart_id;
  24. tr.aces('this.chart_id',this.chart_id);
  25. }
  26. // THIS NEEDS FIXING. I can't figure out how to preprend the chart
  27. // id to the optional parameters.
  28. public function callJavascript(functionName:String, ... optionalArgs ): * {
  29. // the debug player does not have an external interface
  30. // because it is NOT embedded in a browser
  31. if (ExternalInterface.available) {
  32. if ( this.has_id ) {
  33. tr.aces(functionName, optionalArgs);
  34. optionalArgs.unshift(this.chart_id);
  35. tr.aces(functionName, optionalArgs);
  36. }
  37. return ExternalInterface.call(functionName, optionalArgs);
  38. }
  39. }
  40. }
  41. }