ExternalFunction
| Kind of class: | class |
|---|---|
| Inherits from: | Dispatcher |
| Author: | Martijn de Visser |
| Classpath: | org.asapframework.util.system.ExternalFunction |
| File last modified: | Tuesday, 03 October 2006, 09:43:55 |
Class to create handler with, allowing for communication between Javascript and Flash.
This class will fire evens that you can listen to. The events fired will have the same name as they have in Javascript.
Usage:
In Flash, import and instantiate ExternalEvent class:
Next, in HTML, call this JavaScript function and specify the event type and, optionally, a comma delimited string of parameters.
For example:
import org.asapframework.util.system.ExternalFunction; import org.asapframework.util.system.ExternalFunctionEvent; var mExtFunc:ExternalFunction = ExternalFunction.getInstance(); mExtFunc.addEventListener("myCustomEvent", this); var myCustomEvent:Function = function ( e:ExternalFunctionEvent ) { // code goes here... }In your Javascript file (to load in the embedding HTML file), add the following function:
function flashEvent(inSwf, inEvent, inParams) { var divcontainer = "flash_setvariables_" + inSwf; if(!document.getElementById(divcontainer)){ var divholder = document.createElement("div"); divholder.id = divcontainer; document.body.appendChild(divholder); } var divinfo = "<embed src='swf/gateway.swf' FlashVars='lc=" + inSwf + "&ev=" + escape(inEvent) + "," + escape(inParams) + "' width='0' height='0' type='application/x-shockwave-flash'></embed>"; document.getElementById(divcontainer).innerHTML = ""; document.getElementById(divcontainer).innerHTML = divinfo; }As you can see, there is a reference here to a file named 'gateway.swf'. This file acts as an intermediary between Javascript and the ActionScript event. You can obtain a copy of this file (and the souce files) here: http://www.martijndevisser.com/download/externalfunction.zip
Next, in HTML, call this JavaScript function and specify the event type and, optionally, a comma delimited string of parameters.
For example:
<a href="javascript:flashEvent('myFlashFile', 'myCustomEvent', 'myParam1, myParam2');">test...</a>Events broadcast to listeners:
ExternalFunctionEvent Summary
Instance properties
Instance properties inherited from Dispatcher
Class methods
Instance methods
Event handlers
Instance properties
lc
lc:String
(read)
Returns ID of LocalConnection
Class methods
getInstance
static function getInstance (
) : ExternalFunction
Returns reference to singleton instance of ExternalEvent
Instance methods
toString
function toString (
) : String
Event handlers
onFlashEvent
function onFlashEvent (
inEvent:String) : Void
Triggered once an event has been received, fires ExternalFunctionEvent
Events broadcast to listeners:
ExternalFunctionEvent