Created
February 23, 2010 02:22
-
-
Save kara-ryli/311775 to your computer and use it in GitHub Desktop.
How to dispatch Prototype custom events from Flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment