Reply
Logi Nu
webweber
Posts: 2
Registered: ‎10-13-2011
0

Wireless Presenter R400: How to control Flash or Javascript

Hi!

I have a presentation built in Flash / Actionscript. I would like to control it with the R400 but so far I am not able to receive any  (keyboard or mouse) events inside Flash - I tried it running the flashplayer inside an HTML page and standalone. Is there a way of doing this?

As a workaround: if I can receive the events with a listener function in JavaScript, I could then easily pass them on to Flash. Is it possible to receive the events in Javascript?

Thank you for your time!

Andreas

www.motiondraw.com

Logi Nu
webweber
Posts: 2
Registered: ‎10-13-2011
0

Re: Wireless Presenter R400: How to control Flash or Javascript

Maybe this will help someone else:

 

I still haven't found a way to receive the events directly in Flash. But JavaScript receives them:

 

     function keyHandler(e){
        KeyID = e.keyCode;
        alert(KeyID);
    }
    document.onkeypress=keyHandler;

 

Now it's just a matter of passing the value to Flash via ExternalInterface.

 

Here's a working examle: press any key on your keyboard or the R400:

http://www.motiondraw.com/md/as_samples/externalInterfaceExample/ExternalInterfaceExample.html

 

A zip with all the files:

www.motiondraw.com/md/as_samples/externalInterfaceExample/externalInterfaceExample.zip

 

HTH

Andreas Weber

www.motiondraw.com

 

 

// Flash/Actionscript

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.text.TextFieldType;
    import flash.text.TextFieldAutoSize;

    public class ExternalInterfaceExample extends Sprite {
        private var input:TextField;
        private var output:TextField;
        private var sendBtn:smileyfrustrated:prite;

        public function ExternalInterfaceExample() {
 
            output = new TextField();
            output.y = 25;
            output.width = 450;
            output.height = 325;
            output.multiline = true;
            output.wordWrap = true;
            output.border = true;
            output.text = "Initializing...\n";
            addChild(output);

            if (ExternalInterface.available) {
                try {
                    output.appendText("Adding callback...\n");
                    ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
                    if (checkJavaScriptReady()) {
                        output.appendText("JavaScript is ready.\n");
                    } else {
                        output.appendText("JavaScript is not ready, creating timer.\n");
                        var readyTimer:Timer = new Timer(100, 0);
                        readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                        readyTimer.start();
                    }
                } catch (error:smileyfrustrated:ecurityError) {
                    output.appendText("A SecurityError occurred: " + error.message + "\n");
                } catch (error:Error) {
                    output.appendText("An Error occurred: " + error.message + "\n");
                }
            } else {
                output.appendText("External interface is not available for this container.");
            }
        }
        private function receivedFromJavaScript(value:smileyfrustrated:tring):void {
            output.appendText("JavaScript says: keyCode is " + value + "\n");
           
            handleRemoteControlInput(value);
        }
        private function checkJavaScriptReady():Boolean {
            var isReady:Boolean = ExternalInterface.call("isReady");
            return isReady;
        }
        private function timerHandler(event:TimerEvent):void {
            output.appendText("Checking JavaScript status...\n");
            var isReady:Boolean = checkJavaScriptReady();
            if (isReady) {
                output.appendText("JavaScript is ready.\n");
               
                Timer(event.target).stop();
            }
        }
       
        private function handleRemoteControlInput(value:smileyfrustrated:tring) {
            /*
             * Do something with it!
             */
       
        }
 
    }
}

 

 

 

 

 

// HTML JavaScript

 

 

<!-- saved from url=(0014)about:internet -->
 <html lang="en">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>ExternalInterfaceExample</title>
 <script language="JavaScript">
     var jsReady = false;
     function isReady() {
         return jsReady;
     }
     function pageInit() {
         jsReady = true;
         document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
     }
     function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
     function sendToActionScript(value) {
         thisMovie("ExternalInterfaceExample").sendToActionScript(value);
     }
     function sendToJavaScript(value) {
         document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
     }
     
     
     function keyHandler(e){
        KeyID = e.keyCode;
        sendToActionScript(KeyID);
    }
    document.onkeypress=keyHandler;
 </script>
 </head>
 <body onLoad="pageInit();">
 


     <object classid="clsid:smileyvery-happy:27CDB6E-AE6D-11cf-96B8-444553540000"
             id="ExternalInterfaceExample" width="500" height="375"
             codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
         <param name="movie" value="ExternalInterfaceExample.swf" />
         <param name="quality" value="high" />
         <param name="bgcolor" value="#869ca7" />
         <param name="allowScriptAccess" value="sameDomain" />
         <embed src="ExternalInterfaceExample.swf" quality="high" bgcolor="#869ca7"
             width="500" height="375" name="ExternalInterfaceExample" align="middle"
             play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
             type="application/x-shockwave-flash"
             pluginspage="http://www.macromedia.com/go/getflashplayer">
         </embed>
     </object>
 
 </body>
 </html>