Created
October 19, 2010 14:14
-
-
Save muratcorlu/634254 to your computer and use it in GitHub Desktop.
Fire events that can listen by Javascript 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
/* | |
* Flash runs fireFlashEvent function with a event name parameter and | |
* several optional parameters. Javascript can listen these events by | |
* binding with addFlashEventListener function. | |
* | |
* Requires jQuery | |
*/ | |
// Global Document object for caching $(document) selector | |
Document = null; | |
function fireFlashEvent(event) { | |
var args = arguments, | |
argArray = [], | |
index, | |
doc; | |
if (arguments.length == 0) { | |
return false | |
} | |
doc = Document || $(document); | |
for(index = 0; index < args.length; index++) { | |
argArray.push(args[index]) | |
} | |
doc.trigger('flashEvent_' + event, argArray.shift()); | |
} | |
function addFlashEventListener(event, func) { | |
var doc = Document || $(document); | |
doc.bind('flashEvent_' + event, func); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment