0 Replies Latest reply on Apr 17, 2009 10:36 AM by hbstone

    calling JS from AS without user interaction?


      I have an HTML/JS AIR app, and in my initial window I have an embedded SWF. Basic example code follows, using the attached test.swf which attempts to call getURL("javascript:void(callMe('success'));"); every 4 seconds. The real SWF attempts to call a JavaScript function every few minutes (not necessarily at regular intervals), but the method is the same.


      The problem is that the calls only succeed when there is some event occurring on the actual SWF - mouse moving or clicking over the SWF, etc. If the mouse is not moving over (or clicking on) the SWF at the exact time the call is made, it fails silently - no error, nothing to trace, no indication a call was even made.


      This will be on a kiosk/touchscreen application, and I obviously can't ask the user to wiggle their finger around the screen while the SWF plays. I assume the requirement for user interaction is some sort of security "feature", but on this environment there's absolutely no reason for it. I entered the locations of the SWF and its parent folder in the trusted list for Flash's global security settings, but is there some other registry key or setting that will allow these calls to be made?


      For clarification, the page can call functions on the SWF just fine, the problem only occurs when the SWF attempts to call a JavaScript function.


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
              <title>SWF to JS</title>
                  body {
                      background: #000;
                  div {
                      background: #999;
                      height: 20px;
                      padding-left: 10px;
              <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
              <script type="text/javascript" src="lib/air/AIRIntrospector.js"></script>
              <object id="swf" type="application/x-shockwave-flash" width="480" height="320">
                  <param name="allowscriptaccess" value="always">
                  <param name="wmode" value="transparent">
              <div id="count"></div>
              <div id="js-count"></div>
              <script type="text/javascript">
                  var count = 0;
                  var jsCount = 0;
                  var s = document.getElementById("swf");
                  window.onload = function() {
                      var p = document.createElement('param');
                      p.setAttribute("name", "movie");
                      p.setAttribute("value", 'test.swf');
                      setTimeout(loop, 2200); // initial delay before we start counting
                  function callMe(str) {
                      air.trace("called me!", str); // SWF passes "success" here
                  function loop() {
                      var div = document.getElementsByTagName("div");
                      div[0].innerHTML = "callMe() has been called " + count + " times.";
                      div[1].innerHTML = "callMe() SHOULD have been called " + jsCount + " times.";
                      setTimeout(arguments.callee, 4000);