public
Last active

How to dispatch Prototype custom events from Flash

  • Download Gist
Dispatcher.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package {
 
import flash.events.Event
import flash.events.IEventDispatcher;
import flash.external.ExternalInterface;
import CustomEvent;
public class Dispatcher {
private static const FIRE:String = 'Element.fire';
private static const PREFIX:String = 'flash:';
 
private function proxyEvent(_e:Event):void {
var type:String = _e.type.indexOf(':') === -1 ? PREFIX + _e.type : _e.type,
memo:Object = {};
 
if (_e is CustomEvent) {
memo = (_e as CustomEvent).memo;
}
ExternalInterface.call(FIRE, swfId, _e.type, memo);
}
 
private var swfId:String;
public function Dispatcher(target:IEventDispatcher, _swfId) {
swfId = _swfId;
if (ExternalInterface.call(AVAILABLE)) {
// Add you event listeners here
target.addEventListener(Event.ENTER_FRAME, proxyEvent);
}
}
}
}
dispatcher.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13
<!DOCTYPE html>
<div id="container">Alternate Content</div>
<script src="swfobject.js"></script>
<script>
var swfId = "swf", so;
if (! /^[A-Z0-9_]+$/i.test(swfId)) {
throw new Error('ExternalInterface will not work in IE with this ID');
}
so = new SWFObject('flash.swf', swfId, 550, 400, "10", "#000000", true);
so.addParam('allowScriptAccess', 'always');
so.addVariable('swfId', swfId);
so.write('container');
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.