7 Replies Latest reply on Oct 11, 2008 7:41 AM by Newsgroup_User

    Javascript to Flex

    wkolcz Level 1
      I want my html page to broadcast to my flex app before the user either moves to a new page or closes the browser so I can track video plays and results. I have a javascript function in the HTML.

      <SCRIPT LANGUAGE="JavaScript">

      window.onbeforeunload = closingWindow;

      function closingWindow()
      {
      alert('Window Closing');
      videoTracking.tagWithClosed();
      }
      </SCRIPT>

      I added the alert just to see if it was working..

      The name of the id for the swf object is 'videoTracking':
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
      id="videoTracking" width="100%" height="100%"....

      In my actionscript I have inported the flash.external.ExternalInterface and initApp() to addCallBack.

      public function initApp():void {
      ExternalInterface.addCallback("tagWithClosed",windowClosed);
      theVideo.stop();
      }

      I have my function that acts upon the windowClosed function request:

      public function windowClosed():void {
      myTimer.stop()
      var results:int = myTimer.currentCount;
      var action:String = "Window Closed";
      trackerDAO.countIt(addOne, results, action, videoFile);
      theVideo.stop();
      }

      And ideas why its not working? The alert pops when I try to close the browser or move to another page, but the JS is not broadcasting to AS or AS is not doing something right.

      Thanks.
        • 1. Re: Javascript to Flex
          Level 7

          "projectproofing" <webforumsuser@macromedia.com> wrote in message
          news:gclk4b$bjv$1@forums.macromedia.com...
          >I want my html page to broadcast to my flex app before the user either
          >moves to
          > a new page or closes the browser so I can track video plays and results. I
          > have
          > a javascript function in the HTML.
          >
          > <SCRIPT LANGUAGE="JavaScript">
          >
          > window.onbeforeunload = closingWindow;
          >
          > function closingWindow()
          > {
          > alert('Window Closing');
          > videoTracking.tagWithClosed();
          > }
          > </SCRIPT>
          >
          > I added the alert just to see if it was working..
          >
          > The name of the id for the swf object is 'videoTracking':
          > <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
          > id="videoTracking" width="100%" height="100%"....
          >
          > In my actionscript I have inported the flash.external.ExternalInterface
          > and
          > initApp() to addCallBack.
          >
          > public function initApp():void {
          > ExternalInterface.addCallback("tagWithClosed",windowClosed);
          > theVideo.stop();
          > }
          >
          > I have my function that acts upon the windowClosed function request:
          >
          > public function windowClosed():void {
          > myTimer.stop()
          > var results:int = myTimer.currentCount;
          > var action:String = "Window Closed";
          > trackerDAO.countIt(addOne, results, action, videoFile);
          > theVideo.stop();
          > }
          >
          > And ideas why its not working? The alert pops when I try to close the
          > browser
          > or move to another page, but the JS is not broadcasting to AS or AS is not
          > doing something right.

          I don't have time to look it up, but there's another event that is
          cancelable that you can hook into. If you're past that event, it's too
          late.

          HTH;

          Amy


          • 2. Re: Javascript to Flex
            wkolcz Level 1
            umm thanks? The enter seems to work fine, the alert in the same block pops, but it doesn't seem to fire off the event in Flex.
            • 3. Re: Javascript to Flex
              Level 7

              "projectproofing" <webforumsuser@macromedia.com> wrote in message
              news:gcnj6h$164$1@forums.macromedia.com...
              > umm thanks? The enter seems to work fine, the alert in the same block
              > pops, but it doesn't seem to fire off the event in Flex.

              This is where I look up this sort of information when I'm not sure
              http://msdn.microsoft.com/en-us/library/ms535873(VS.85).aspx#


              • 4. Re: Javascript to Flex
                wkolcz Level 1
                Its not the window hook that is causing a problem, that works fine as far as I can tell. As the window closes, that hook is captured. The alert is telling me such. The problem is with either the JS that broadcasts to Flex or in the Flex function itself.
                • 5. Re: Javascript to Flex
                  Level 7

                  "projectproofing" <webforumsuser@macromedia.com> wrote in message
                  news:gcnuu1$fqd$1@forums.macromedia.com...
                  > Its not the window hook that is causing a problem, that works fine as far
                  > as I
                  > can tell. As the window closes, that hook is captured. The alert is
                  > telling me
                  > such. The problem is with either the JS that broadcasts to Flex or in the
                  > Flex
                  > function itself.

                  How much time have you spent on this, and how much would it cost you to find
                  and try the other event?


                  • 6. Re: Javascript to Flex
                    g-s-b Level 1

                    Try...

                    Using Flash's the external interface, add a callback function in your Flex. Just in front of your "alert" call that callback function.

                    • 7. Re: Javascript to Flex
                      Level 7

                      "g-s-b" <webforumsuser@macromedia.com> wrote in message
                      news:gcqde0$bve$1@forums.macromedia.com...
                      >
                      > Try...
                      >
                      > Using Flash's the external interface, add a callback function in your
                      > Flex. Just in front of your "alert" call that callback function.
                      >

                      At that point, the embedded Flash movie has already been destroyed, so it
                      won't do anything.