Skip to content

Instantly share code, notes, and snippets.

@yoko
Created October 1, 2008 07:34
Show Gist options
  • Save yoko/14048 to your computer and use it in GitHub Desktop.
Save yoko/14048 to your computer and use it in GitHub Desktop.
SWFObject wrapper plugin
package {
import flash.display.Sprite;
import flash.external.ExternalInterface;
[SWF(frameRate=1, background=0x000000)]
public class Hello extends Sprite {
public function Hello() {
ExternalInterface.marshallExceptions = true;
ExternalInterface.addCallback('hello', function():String {
return 'hello!';
});
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jQuery.fl</title>
<link rel="stylesheet" type="text/css" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css"/>
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js"></script>
<script type="text/javascript" src="jquery.fl.js"></script>
</head>
<body>
<h1 id="qunit-header">jQuery.fl</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<script type="text/javascript">
module('jQuery.fl', {
teardown: function() {
$('#hello_with_external').remove();
}
});
test('emded swf', 4, function() {
$('body').fl({
src : 'Hello.swf',
id : 'hello_with_external',
width : 1,
height: 1,
params: {
allowscriptaccess: 'always'
}
});
var swf = $('#hello_with_external');
equals(swf.length, 1);
equals(swf.attr('width'), 1);
equals(swf.attr('height'), 1);
equals($('param[name="allowscriptaccess"]', swf).val(), 'always');
});
test('get External Interface object', 1, function() {
$('body').fl({
src : 'Hello.swf',
id : 'hello_with_external',
width : 1,
height: 1,
params: {
allowscriptaccess: 'always'
}
});
stop();
setTimeout(function() {
start();
var swf = $('#hello_with_external').fl();
equals(swf.hello(), 'hello!', 'ExternalInterface.addCallback');
}, 1000);
});
</script>
</body>
</html>
(function($) {
$.fn.fl = function(o) {
if (!o) {
var id = this.attr('id');
return $.browser.msie ? window[id] : document[id];
}
// http://la.ma.la/blog/diary_200702152107.htm
// doesn't work for unknown reason..
// if (typeof arguments[0] == 'string') {
// var method = arguments[0];
// var args = $.makeArray(arguments).slice(1);
//
// var id = this.attr('id');
// var fl = $.browser.msie ? window[id] : document[id];
//
// if (fl && typeof fl[method] == 'function') {
// var params = [];
// $.each(args, function(i) { params.push('_'+i); });
//
// var p = params.join();
// Function(p, 'this('+p+')').apply(fl[method], args);
// }
// return this;
// }
o = $.extend(true, {
version: '9.0.47',
params : {
wmode: 'transparent'
}
}, o);
if (swfobject.hasFlashPlayerVersion(o.version)) {
o.attrs = $.extend(o.attrs || {}, {
data : o.src,
width : o.width,
height: o.height
});
if (o.flashvars) o.params.flashvars = $.param(o.flashvars);
var element = o.id ?
$('<div id="'+o.id+'"/>').appendTo(this) :
this;
swfobject.createSWF(
o.attrs,
o.params,
element.attr('id')
);
}
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment