1 Reply Latest reply on Feb 13, 2008 6:01 AM by Newsgroup_User

    Call Javascript from Flash (k)

    Level 7
      I've done this many times before(use getURL to call Javascript in the
      HTML page that houses the SWF), but for some reason this just isn't
      working this tiime.

      I have a transparent DIV in my html.

      I have a text link in my HTML:
      Make it <a href="#"
      onclick="MM_callJS('opacity(\'L_20\',0,100,2000)')">Fade In
      </a>

      that calls this Javascript:

      <script type="text/javascript">
      <!--
      function opacity(id, opacStart, opacEnd, millisec) {
      //speed for each frame
      var speed = Math.round(millisec / 100);
      var timer = 0;

      //determine the direction for the blending, if start and end are
      the same nothing happens
      if(opacStart > opacEnd) {
      for(i = opacStart; i >= opacEnd; i--) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer *
      speed));
      timer++;
      }
      } else if(opacStart < opacEnd) {
      for(i = opacStart; i <= opacEnd; i++)
      {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer *
      speed));
      timer++;
      }
      }
      }

      //change the opacity for different browsers
      function changeOpac(opacity, id) {
      var object = document.getElementById(id).style;
      object.opacity = (opacity / 100);
      object.MozOpacity = (opacity / 100);
      object.KhtmlOpacity = (opacity / 100);
      object.filter = "alpha(opacity=" + opacity + ")";
      }

      function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
      }
      //-->
      </script>


      It works perfectly when I click on the text HTML text link. When I put
      this code in the last frame of my Flash movie though, nothing.

      getURL("javascript:MM_callJS('opacity(\'FadeLayer\',0,100,2000)')");

      Any thoughts?

      -Kirk
        • 1. Re: Call Javascript from Flash (k)
          Level 7
          Anybody? Anybody? Bueller? Bueller?


          W. Kirk Lutz wrote:
          > I've done this many times before(use getURL to call Javascript in the
          > HTML page that houses the SWF), but for some reason this just isn't
          > working this tiime.
          >
          > I have a transparent DIV in my html.
          >
          > I have a text link in my HTML:
          > Make it <a href="#"
          > onclick="MM_callJS('opacity(\'L_20\',0,100,2000)')">Fade In
          > </a>
          >
          > that calls this Javascript:
          >
          > <script type="text/javascript">
          > <!--
          > function opacity(id, opacStart, opacEnd, millisec) {
          > //speed for each frame
          > var speed = Math.round(millisec / 100);
          > var timer = 0;
          >
          > //determine the direction for the blending, if start and end are the
          > same nothing happens
          > if(opacStart > opacEnd) {
          > for(i = opacStart; i >= opacEnd; i--) {
          > setTimeout("changeOpac(" + i + ",'" + id + "')",(timer *
          > speed));
          > timer++;
          > }
          > } else if(opacStart < opacEnd) {
          > for(i = opacStart; i <= opacEnd; i++)
          > {
          > setTimeout("changeOpac(" + i + ",'" + id + "')",(timer *
          > speed));
          > timer++;
          > }
          > }
          > }
          >
          > //change the opacity for different browsers
          > function changeOpac(opacity, id) {
          > var object = document.getElementById(id).style;
          > object.opacity = (opacity / 100);
          > object.MozOpacity = (opacity / 100);
          > object.KhtmlOpacity = (opacity / 100);
          > object.filter = "alpha(opacity=" + opacity + ")";
          > }
          >
          > function MM_callJS(jsStr) { //v2.0
          > return eval(jsStr)
          > }
          > //-->
          > </script>
          >
          >
          > It works perfectly when I click on the text HTML text link. When I put
          > this code in the last frame of my Flash movie though, nothing.
          >
          > getURL("javascript:MM_callJS('opacity(\'FadeLayer\',0,100,2000)')");
          >
          > Any thoughts?
          >
          > -Kirk