Permalink
Browse files

Add Swiff from MooTools Core

  • Loading branch information...
1 parent 7b9a879 commit 1aaf018f1a4030c622103f90cd9d5eac3478e531 @arian arian committed Sep 1, 2012
Showing with 204 additions and 0 deletions.
  1. +90 −0 Docs/Utilities/Swiff.md
  2. +113 −0 Source/Utilities/Swiff.js
  3. +1 −0 package.yml
View
@@ -0,0 +1,90 @@
+# Class: Swiff {#Swiff}
+
+Creates and returns a Flash object using supplied parameters.
+
+### Syntax:
+
+ var mySwiff = new Swiff(path[, options]);
+
+### Arguments:
+
+1. path - (*string*) The path to the SWF file.
+2. options - (*object*, optional) See Options below.
+
+### Options:
+
+* id - (*string*: defaults to 'Swiff\_' + unique id) The id of the SWF object.
+* width - (*number*: defaults to 1) The width of the SWF object.
+* height - (*number*: defaults to 1) The height of the SWF object.
+* container - (*element*) The container the SWF object gets injected in.
+* params - (*object*) Parameters to be passed to the SWF object (wmode, bgcolor, allowScriptAccess, loop, etc.).
+ * allowScriptAccess - (*string*: defaults to always) The domain that the SWF object allows access to.
+ * quality - (*string*: defaults to 'high') The render quality of the movie.
+ * swLiveConnect - (*boolean*: defaults to true) the swLiveConnect parameter to allow remote scripting.
+ * wMode - (*string*: defaults to 'window') Changes the way the SWF is displayed in the browser.
+* properties - (*object*) Additional attributes for the object element.
+* vars - (*object*) Vars will be passed to the SWF as query string in flashVars.
+* callBacks - (*object*) Functions to call from the SWF. These will be available globally in the movie, and bound to the object.
+
+### Returns:
+
+* (*element*) A new HTML object element.
+
+### Example:
+
+ var obj = new Swiff('myMovie.swf', {
+ id: 'myBeautifulMovie',
+ width: 500,
+ height: 400,
+ params: {
+ wMode: 'opaque',
+ bgcolor: '#ff3300'
+ },
+ vars: {
+ myVariable: myJsVar,
+ myVariableString: 'hello'
+ },
+ callBacks: {
+ load: myOnloadFunc
+ }
+ });
+
+### Note:
+
+1. Although Swiff returns the object, this element will NOT have any [Element][] methods applied to it.
+2. The $ function on an object/embed tag will only return its reference without further processing.
+
+## Swiff Function: remote {#Swiff:remote}
+
+Calls an ActionScript function from JavaScript.
+
+### Syntax:
+
+ var result = Swiff.remote(obj, fn[, arg, arg, arg ...]);
+
+### Arguments:
+
+1. obj - (*element*) A Swiff instance (a HTML object element).
+2. fn - (*string*) The function name to execute in the SWF.
+3. arg - (*mixed*) Any number of arguments to pass to the named function.
+
+### Returns:
+
+* (*mixed*) The ActionScript function's result.
+
+### Example:
+
+ var obj = new Swiff('myMovie.swf');
+ alert(Swiff.remote(obj, 'myFlashFn')); // alerts "This is from the .swf file!".
+
+### Note:
+
+The SWF file must be compiled with the ExternalInterface component. See the Adobe documentation on [External Interface][] for more information.
+
+### Credits:
+
+- Flash detection and Internet Explorer/Flash Player 9 fix adapted from [SWFObject][].
+
+[Element]: /core/Element/Element
+[External Interface]: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html
+[SWFObject]: http://code.google.com/p/swfobject/
View
@@ -0,0 +1,113 @@
+/*
+---
+
+name: Swiff
+
+description: Wrapper for embedding SWF movies. Supports External Interface Communication.
+
+license: MIT-style license.
+
+credits:
+ - Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.
+
+requires: [Core/Options, Core/Object, Core/Element]
+
+provides: Swiff
+
+...
+*/
+
+(function(){
+
+var Swiff = this.Swiff = new Class({
+
+ Implements: Options,
+
+ options: {
+ id: null,
+ height: 1,
+ width: 1,
+ container: null,
+ properties: {},
+ params: {
+ quality: 'high',
+ allowScriptAccess: 'always',
+ wMode: 'window',
+ swLiveConnect: true
+ },
+ callBacks: {},
+ vars: {}
+ },
+
+ toElement: function(){
+ return this.object;
+ },
+
+ initialize: function(path, options){
+ this.instance = 'Swiff_' + String.uniqueID();
+
+ this.setOptions(options);
+ options = this.options;
+ var id = this.id = options.id || this.instance;
+ var container = document.id(options.container);
+
+ Swiff.CallBacks[this.instance] = {};
+
+ var params = options.params, vars = options.vars, callBacks = options.callBacks;
+ var properties = Object.append({height: options.height, width: options.width}, options.properties);
+
+ var self = this;
+
+ for (var callBack in callBacks){
+ Swiff.CallBacks[this.instance][callBack] = (function(option){
+ return function(){
+ return option.apply(self.object, arguments);
+ };
+ })(callBacks[callBack]);
+ vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack;
+ }
+
+ params.flashVars = Object.toQueryString(vars);
+ if (Browser.ie){
+ properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
+ params.movie = path;
+ } else {
+ properties.type = 'application/x-shockwave-flash';
+ }
+ properties.data = path;
+
+ var build = '<object id="' + id + '"';
+ for (var property in properties) build += ' ' + property + '="' + properties[property] + '"';
+ build += '>';
+ for (var param in params){
+ if (params[param]) build += '<param name="' + param + '" value="' + params[param] + '" />';
+ }
+ build += '</object>';
+ this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild;
+ },
+
+ replaces: function(element){
+ element = document.id(element, true);
+ element.parentNode.replaceChild(this.toElement(), element);
+ return this;
+ },
+
+ inject: function(element){
+ document.id(element, true).appendChild(this.toElement());
+ return this;
+ },
+
+ remote: function(){
+ return Swiff.remote.apply(Swiff, [this.toElement()].append(arguments));
+ }
+
+});
+
+Swiff.CallBacks = {};
+
+Swiff.remote = function(obj, fn){
+ var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>');
+ return eval(rs);
+};
+
+})();
View
@@ -67,6 +67,7 @@ sources:
- "Source/Utilities/Hash.Cookie.js"
- "Source/Utilities/IframeShim.js"
- "Source/Utilities/Table.js"
+ - "Source/Utilities/Swiff.js"
- "Source/Interface/HtmlTable.js"
- "Source/Interface/HtmlTable.Zebra.js"
- "Source/Interface/HtmlTable.Sort.js"

0 comments on commit 1aaf018

Please sign in to comment.