2 Replies Latest reply on Aug 21, 2007 2:24 PM by PhilBailey

    Global Access to Listener Function

      Hello All --

      I am using a third-party Flash add-on tool that will let me get a device's battery level (among other things) via listeners. The following code is in my first actionscript frame:

      import ssp.device.*;
      var statusListener:Object = new Object();

      // set-up status listener to get battery level
      statusListener.getBatteryLevel = function(e)
      _global.batteryLevel = e;


      The final line in the preceding script successfully sets _global.batteryLevel. The problem is that the script is run only once, when the application starts. What I need to be able to do is to call Status.getBatteryLevel() from a battery monitoring movieclip within my main movie. The movieclip runs constantly to update a display of remaining battery charge.

      Unfortunately, whenever I try to execute Status.getBatteryLevel() from any frame other than the one where the listener is set-up, the function does not work. Is there something that I need to do to make the function call available globally?


      -- Phil
        • 1. Re: Global Access to Listener Function
          Greg Dove Level 4
          It seems unusual that the Status object only dispatches events when you request them... but perhaps its just a model I'm not used to. Anyhow...

          Where is your monitoring clip relative to the timeline that holds Status?

          If its also in the same timeline then you should be able to get to Status from its timeline by using


          I never really use the _global object, but I guess you could do that too.
          _global.getBatteryLevel = Status.getBatteryLevel;

          then just use

          I think that would work.

          • 2. Re: Global Access to Listener Function
            PhilBailey Level 1
            Hi GWD --

            Using the _parent. prefix probably wouldn't work since I have tried the function call right from another frame in the same level. Fortunately, your suggestion to use the _global scope worked great! Thanks very much!

            -- Phil