Using Javascript with RevBrowser to control a Flash Movie

Ken Ray kray at
Tue Oct 11 12:39:36 EDT 2011

On Oct 11, 2011, at 10:23 AM, Alejandro Tejada wrote:

> Hi all,
> I am looking for a stack with scripts examples
> of controling a Flash Movie running inside a 
> Revbrowser control using Javascript.
> Any pointers to stacks and information to
> solve this task is welcome.

I'm doing this with a Flash "player" region that runs a streaming video that I need to communicate with to tell it to stop, play, etc.

It's an HTML page that includes a Flash region with a block like this (watch the line wraps):

		<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,0,0" width="100%" height="100%" id="MyPlayer" align="middle">
			<param name="allowScriptAccess" value="sameDomain" />
			<param name="allowFullScreen" value="false" />
			<param name="movie" value="MyPlayer.swf" />
			<param name="quality" value="high" /><param name="bgcolor" value="#000000" />	
			<embed src="MyPlayer.swf" quality="high" bgcolor="#000000" width="100%" height="100%" name="MyPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="" />

The page also includes this Javascript inside the <body> tag to be called from LC:

	<script language="JavaScript">  
		function getFlashMovie(movieName) {
			var isIE = navigator.appName.indexOf("Microsoft") != -1;   
			return (isIE) ? window[movieName] : document[movieName];  
		function jsTellFlash(pText, pParam1) {
			var result = getFlashMovie("MyPlayer").sendTextToFlash(pText, pParam1);
			return (result);

In LC, I use this handler to communicate with the browser region (where I've stored the browser ID of the revBrowser control in the uBrowserID of the stack):

	on TellSWF pWhat,pParam1
	    get revBrowserExecuteScript(the uBrowserID of this stack, "result = jsTellFlash('" & pWhat & "','" & pParam1 & "');")
	    if word 1 of it contains "Error" then
	      answer "Error executing command '" & pWhat & "':" &cr & cr & it
	      return it
	    end if
	  catch pErr
	    -- do what you want with the error
	  end try
	end TellSWF

Finally, in the SWF itself there is an FLVPlaybackRegion control called "myvideo" with this code in frame 1:

	import flash.external.ExternalInterface;

	function getTextFromJavascript(str:String, tParam:String):String 
		switch (str) {
			case ("play"):;   // this calls a separate Flash function
				return ("OK");
			case ("pause"):
				myvideo.pause();   // this calls a separate Flash function
				return ("OK");
			case ("stop"):
				return ("OK");
			// add whatever commands you want to trap to the switch
				return ("Error: Command '" + str + "' not recognized.");
	ExternalInterface.addCallback("sendTextToFlash", getTextFromJavascript);

So this means that when I want the video to play, I issue:

	TellSWF "play"

which in turn calls "revBrowserExecuteScript"…
	which calls the "jsTellFlash()" Javascript function in the page…
		which calls "sendTextToFlash" through the external SWF interface…
			which finally runs "getTextFromJavaScript()" and executes the "play"

			it then returns "OK"…
		which sets the variable "result" in jsTellFlash() to "OK"…
	which returns the variable "result" ("OK") to the revBrowserExecuteScript call…
which finally puts *its* result ("OK") into "it"

(I'm not testing for "OK", only for "Error", but you can see how this operates)

Whew! A lot of baton-passing but it works! This may be more than you asked for, so just take the parts you need…


Ken Ray
Sons of Thunder Software, Inc.
Email: kray at
Web Site:	

More information about the Use-livecode mailing list