- Top
- Summary
- Constructors
- Class properties
- Instance properties
- Class methods
- Instance methods
- Event handlers
ExternalFunction
| Kind of class: | class |
|---|---|
| Inherits from: | Dispatcher |
| Author: | Martijn de Visser |
| Classpath: | org.asapframework.util.system.ExternalFunction |
| File last modified: | Wednesday, 04 October 2006, 01:10:46 |
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.
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:
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 broadcasted to listeners:
ExternalFunctionEvent
Summary
Constructor
Class properties
Instance properties
Instance properties inherited from Dispatcher
Class methods
- getInstance : ExternalFunction
- Returns reference to singleton instance of ExternalEvent
Instance methods
- toString : String
Event handlers
- onFlashEvent (inEvent:String) : Void
- Triggered once an event has been received, fires ExternalFunctionEvent
Constructor
ExternalFunction
private function ExternalFunction (
)
Private constructor, use getInstance to refer to singleton instance
Class properties
instance
Instance properties
handler
private handler:LocalConnection
(read)
lc
lc:String
(read)
Returns ID of LocalConnection
lcID
private lcID:String
(read)
Class methods
getInstance
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 broadcasted to listeners:
ExternalFunctionEvent