Using Javascript with RevBrowser to control a Flash Movie

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Javascript with RevBrowser to control a Flash Movie

Alejandro Tejada
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.

Thanks in advance!

Al

Reply | Threaded
Open this post in threaded view
|

Re: Using Javascript with RevBrowser to control a Flash Movie

Ken Ray

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):

        <noscript>
                <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,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="http://www.adobe.com/go/getflashplayer" />
                </object>
        </noscript>

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);
                }
        </script>

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
          try
            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
            else
              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.events.Event;
        import flash.external.ExternalInterface;

        function getTextFromJavascript(str:String, tParam:String):String
        {  
                switch (str) {
                        case ("play"):
                                myvideo.play();   // this calls a separate Flash function
                                return ("OK");
                        case ("pause"):
                                myvideo.pause();   // this calls a separate Flash function
                                return ("OK");
                        case ("stop"):
                                myvideo.stop();
                                return ("OK");
                        // add whatever commands you want to trap to the switch
                        default:
                                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…

Enjoy!

Ken Ray
Sons of Thunder Software, Inc.
Email: [hidden email]
Web Site: http://www.sonsothunder.com/       

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Using Javascript with RevBrowser to control a Flash Movie

Alejandro Tejada
In reply to this post by Alejandro Tejada
Hi all,

These are example of using Javascript to
control swf movies:

http://www.russellchun.com/?p=174
http://www.flashcentral.com/Tech/HawaiiMap/

How could I talk to the javascript in these
webpages from LliveCode?

Thanks in advance!

Al
Reply | Threaded
Open this post in threaded view
|

Re: Using Javascript with RevBrowser to control a Flash Movie

Alejandro Tejada
In reply to this post by Ken Ray
Wow! Ken, this a really complex mechanism. :-O

Many thanks for sharing this code! After I subdue this
headache (dogs barking do not let me sleep last night)
I will start experimenting.

Hopefully, in a near future, Chipp Walters would step in
and code a flash player dll (that should be a lot less
difficult than a browser dll) :-D

Have a great good day! :-D

Al
Reply | Threaded
Open this post in threaded view
|

Re: Using Javascript with RevBrowser to control a Flash Movie

Colin Holgate-2
In reply to this post by Alejandro Tejada
That is an ActionScript 1.0 swf, and is using a technique that is so old that it isn't in the Flash help anymore. It seems to get a pointer to the swf on the page, and calls things like TGotoFrame to make the Flash go to that frame.

I guess it doesn't matter that it's ancient, if you do the same Javascript as is used in this frame:

http://www.flashcentral.com/Tech/HawaiiMap/story.htm

it ought to work.


On Oct 11, 2011, at 12:49 PM, Alejandro Tejada wrote:

> http://www.flashcentral.com/Tech/HawaiiMap/
>
> How could I talk to the javascript in these
> webpages from LliveCode?

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Using Javascript with RevBrowser to control a Flash Movie

Alejandro Tejada
Hi Colin,

Colin Holgate-2 wrote
That is an ActionScript 1.0 swf, and is using a technique that is so old that it isn't in the Flash help anymore. It seems to get a pointer to the swf on the page, and calls things like TGotoFrame to make the Flash go to that frame.
I guess it doesn't matter that it's ancient, if you do the same Javascript as is used in this frame:
http://www.flashcentral.com/Tech/HawaiiMap/story.htm
it ought to work.
It's amazing that current SWF player supports syntax from version 1.0!!!

The compressed file:
http://www.flashcentral.com/Tech/HawaiiMap/Hawaii.zip
contains four html files and 3 swf movies.

Looks like embedding cue points could do exactly what I want:
http://www.ioncannon.net/web-design/109/metadata-cuepoint-flash-video-flvtool/

Have a nice day!

Al