royale-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] aharui closed pull request #335: Ajwfrost/externalinterface
Date Thu, 01 Nov 2018 19:25:29 GMT
aharui closed pull request #335: Ajwfrost/externalinterface
URL: https://github.com/apache/royale-asjs/pull/335
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/external/ExternalInterface.as
b/frameworks/projects/MXRoyale/src/main/royale/mx/external/ExternalInterface.as
index 5b9df426f..7f15783f8 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/external/ExternalInterface.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/external/ExternalInterface.as
@@ -18,29 +18,163 @@
 
 package mx.external
 {
-	
-
-		
-	public final class ExternalInterface
+	COMPILE::SWF
 	{
-		public function ExternalInterface()
-		{
-			super();
-		}
-		private var	available : Boolean;
-		public static function get available():Boolean
-		{
-			return available;
-		}
-		public static function addCallback(functionName:String, closure:Function):void
-		{
-		}
-		public static function call(functionName:String, ... arguments):*
-		{
-			return null;
-		}
-		
+		import flash.external.ExternalInterface;
 	}
-	
-	
+	/**
+	 * The ExternalInterface class provides a mechanism for a Royale application to communicate
with other JavaScript functionality present within the web page.
+	 *
+	 * @langversion 3.0
+	 * @playerversion Flash 9.0
+	 * @playerversion AIR 1.0
+	 * @productversion Royale 0.9
+     * 
+     *  @royalesuppresspublicvarwarning
+	 */
+    public final class ExternalInterface
+    {
+
+        /**
+         * Indicates whether this player is in a container that offers an external interface.
+         * If the external interface is available, this property is true; otherwise, it is
false.
+         */
+        public static function get available():Boolean
+        {
+            COMPILE::SWF
+            {
+                return flash.external.ExternalInterface.available;
+            }
+            COMPILE::JS
+            {
+                return true;
+            }
+        }
+        
+        /**
+         * Indicates whether the external interface should attempt to pass ActionScript exceptions
+         * to the current browser and JavaScript exceptions to the player.
+         * When running as a SWF: default is false. You must explicitly set this property
to true
+         * to catch JavaScript exceptions in ActionScript and to catch ActionScript exceptions
in JavaScript.
+         * When running as HTML, this is always true and cannot be changed.
+         */
+        public static function get marshallExceptions():Boolean
+        {
+            COMPILE::SWF
+            {
+                return flash.external.ExternalInterface.marshallExceptions;
+            }
+            COMPILE::JS
+            {
+                return true;
+            }
+        }
+        /**
+         * @private
+         */
+        public static function set marshallExceptions(val:Boolean):void
+        {
+            COMPILE::SWF
+            {
+                flash.external.ExternalInterface.marshallExceptions = val;
+            }
+            COMPILE::JS
+            {
+                if (!val) trace("WARNING: trying to set ExternalInterface.marshallExceptions
to false; not supported in Royale");
+            }
+        }
+        
+        /**
+         * @private
+         * If we're using an HTML element to hang our callbacks off,
+         * the ID of this can be adjusted via this attribute
+         */
+         COMPILE::JS
+         private static var _objectID : String = "ExternalInterface";
+        
+        /** Returns the id attribute of the Flash Player object if running as a SWF,
+         *  or of the HTML element that is used for hooking up callback objects if
+         *  running in HTML (default then is <code>ExternalInterface</code>).
+         *  Read-only in SWF mode; read-write in JS mode. This needs to be set prior
+         *  to any calls to <code>addCallback</code>.
+         */
+        public static function get objectID():String
+        {
+            COMPILE::SWF
+            {
+                return flash.external.ExternalInterface.objectID;
+            }
+            COMPILE::JS
+            {
+                return _objectID;
+            }
+        }
+        
+        COMPILE::JS
+        public static function set objectID(value:String):void
+        {
+            _objectID = value;
+        }
+
+        /** Registers an ActionScript method as callable from the container.
+         *  After a successful invocation of addCallBack(), the registered
+         *  function in the player can be called by JavaScript.
+         *
+         *  The JavaScript needs to obtain the appopriate element (set via <code>objectID</code>
+         *  and then call the function as a property of this element. For example
+         *  if <code>addCallback</code> has been called with <code>functionName>/code>
+         *  set to "myFunction", the call can be made by:
+         *  <code>document.getElementById("ExternalInterface").myFunction(args);</code>
+         *
+         * @param functionName The name by which the browser can invoke the function.
+         * @param closure The function closure to invoke.
+         */
+        public static function addCallback(functionName:String, closure:Function):void
+        {
+            COMPILE::SWF
+            {
+                flash.external.ExternalInterface.addCallback(functionName, closure);
+            }
+            COMPILE::JS
+            {
+                // use a simple script object to hang our callback properties off..
+                var extInt = document.getElementById(_objectID);
+                if (!extInt)
+                {
+                    extInt = document.createElement("script");
+                    extInt.id = _objectID;
+                    document.body.appendChild(extInt);
+                }
+                extInt[functionName] = closure;
+            }
+        }
+        
+        /** Calls a function exposed by the browser, passing zero or more arguments.
+         *  If the function is not available, the call returns <code>null</code>,
+         *  otherwise it returns the value provided by the function.
+         *
+         * @param functionName The name of the JavaScript function to call.
+         * @param ... args The arguments to pass to the JavaScript function in the browser.
+         */
+        public static function call(functionName:String, ... args):*
+        {
+            COMPILE::SWF
+            {
+                args.unshift(functionName);
+                return flash.external.ExternalInterface.call.apply(null, args);
+            }
+            COMPILE::JS
+            {
+                // find a function with the name...
+                var fnc : Function = window[functionName];
+                if (fnc)
+                {
+                    return fnc.apply(null, args);
+                }
+                return null;
+            }
+        }
+        
+    }
 }
+


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message