开发者

Problem with Flash and JavaScript Communication

I have an AS2 Flash SWF that is calling another AS2 Flash File using loadMovieNum("flash.swf",2) and a JavaScript file that ca开发者_StackOverflow社区lls a function on page using a timer. This is what I get in Firefox with Flash 10 (IE8 gives no error message):

uncaught exception: Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.].

What is going wrong? I can't see a problem. It is suppose to clear the contents of the embedded swf and use a Flash alert dialog to confirm Yes or No.

Flash:

import flash.external.ExternalInterface;
import mx.controls.Alert;

System.security.allowDomain("mydomain.com");

function getTimeOut()
{
 // Show alert dialog box
 _level2._visible = false;
 Alert.show("You are about to Timeout. Do you want to continue using Courseware?", "Timeout", Alert.YES |
 Alert.NO, this, myClickHandler);
}

ExternalInterface.addCallback("timeOut", this, getTimeOut);

this.onMouseDown = function(){
 //if not on login
 getURL("javascript:startTimer();");
};

var myClickHandler:Function = function (evt_obj:Object) {
 switch (evt_obj.detail) {
  case Alert.YES :
   getURL("javascript:buttonEvent('yes');");
   break;
  case Alert.NO :
   getURL("javascript:buttonEvent('no');");
   break;
 }
 _level2._visible = true;
};

//load courseware
loadMovieNum("embedded.swf",2);

JavaScript:

<script type="text/javascript">
  // <![CDATA[

  var so = new SWFObject("main.swf", "mainMovie", "100%", "100%", "9", "#083770");
  so.addParam("scale", "noscale");
  so.addParam("quality", "high");
  so.addParam("allowScriptAccess","always");
        so.write("flashcontent");

  var timerMin = '<?php echo($timerMinutes); ?>';
  var timer;
  var timer2;

  function startTimer()
  {
   var timerMill = 0;
   clearTimeout(timer);
   timerMill = getMillis();
   timer = setTimeout ( 'stopTimer()', timerMill );
  }

  function stopTimer()
  {
   clearTimeout(timer);
   timer2 = setTimeout( 'redirectPage()', 60000);

   //call flash function
   getFlashMovie("mainMovie").timeOut();
  }

  function buttonEvent(evt)
  {
   if(evt == 'yes')
   {
    clearTimeout(timer2);
    startTimer();
   }
   else
   {
    clearTimeout(timer2);
    redirectPage();
   }
  }

  function getMillis()
  {
   var milliseconds = 300000;

   if(timerMin == parseInt(timerMin))
   {
    //convert to milliseconds
    //60000 milliseconds in 1 minute
    milliseconds = (parseInt(timerMin)) * 60000;
   }

   return milliseconds;
  }

  function getFlashMovie(movieName)
  {
   var isIE = navigator.appName.indexOf("Microsoft") != -1;
   return (isIE) ? window[movieName] : document[movieName];
   //return document.getElementById(movieName);
  }

  function redirectPage()
  {
   top.location = "timeout.php?t=<?php echo($timerMinutes); ?>";
  }

  // ]]>
 </script>


Same old story - NPObject.

I took Flash out of the picture and was able to achieve the same thing using CSS and JavaScript. The fix for this is to create a policy file for Flash but for something so simple I just went another direction so not to debug.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜