jQuery Plugin: externalInterface

Posted on Mar 20, 2010 @ 11:46 PM

A jQuery plugin for communication between ActionScript and Javascript . Licensed jointly under the GPL and MIT licenses.

This plugin has been tested with jQuery 1.3.2 and 1.4.2.

 

USAGE:

Requires jQuery to be loaded before the plugin. To use externalInterface, use jQuery to select the Flash movie by id, and then call the externalInterface method. The only required arguments are the method name you are calling in your ActionScript External Interface. Example: $('#myFlashMovie').externalInterface({method:'flashMethodToCall'});

You can also pass arguments to your Actionscript ExternalInterface method, a callback function for success, and a callback function for an error. Example: $('#myFlashMovie').externalInterface({method:'flashMethodToCall', args:'args for actionscript', success:function(data){ alert('success! flash returned: ' + data); },error:function(error){ alert('there was an error: ' + error); }});

 

DEMO:

Click here for a demo of externalInterface.

 

DOWNLOAD:

jquery.externalinterface.js

(function($)
{
	$.fn.externalInterface = function(args)
	{
		this.each(function()
		{
			if(typeof(args.method) != 'undefined')
			{
				try
				{
					if(typeof(args.args) != 'undefined')
					{
						var data = this[args.method](args.args);
					}
					else
					{
						var data = this[args.method]();
					}
					
					if(typeof(args.success) != 'undefined')
					{
						args.success(data);
					}
				}
				catch(error)
				{
					if(typeof(args.error) != 'undefined')
					{
						args.error(error);
					}
				}
			}
		});
	
		return this;
	};
})(jQuery);

30 Comments

Click For New Security Code Please enter the security code: