5 Replies Latest reply on May 12, 2006 6:28 PM by samdl1

    variable listener

      Is it posible to listen for a variable to change and then call a function based on the variables new value?
        • 1. Re: variable listener
          samdl1 Level 1
          Perhaps you could try and call the function as the variable changes eg
          if it changes with users clicking a button try
          my_button.onRelease = my_function() {

          but its very difficult to answer your question without being more specific
          If you post or pm more info perhaps I can help

          • 2. Re: variable listener
            LSNsaltlamp Level 1
            I have a function that is dependant on a variable’s value. Basically:
            if (variable == 2) {
            I need this string to constantly check the value of the variable without creating and infinite loop.
            • 3. Re: variable listener
              blemmo Level 1
              Check out Object.watch(), it looks for a property of an object and calls a function when it's changed. If you use this object property instead of a 'normal' variable, you can define a function that gets executed when the property changes, and has access to the property values. Because MovieClips are objects too, you could use the playing MC to watch for one of its properties:
              function watchFoo(prop, oldVal, newVal){
              foo = "bar";

              The watcher method gets these 3 parameters (name, old and new value of the property), but can get more. See the Flash Help for a good example.

              • 4. Re: variable listener
                samdl1 Level 1
                Ok, I think that you may be looking at this from the wrong way round. Instead of checking the variable's content indescriminantly try checking the content specifically when the variable is changed eg if the variable is controlled by a button

                my_btn.onRelease = function() {
                if (variable == 2) {
                // code

                This should work for any case as the variable has to change via some interaction (however it is slightly more complicated if the variable is changed at a keyframe)

                If I've still not helped please post how the variable is controlled

                • 5. Re: variable listener
                  samdl1 Level 1
                  blemmo beat me to the post...his method will of course work (its blemmo!) but it may overcomplicate the issue if you simply want to discern between two different options and change the movie based on the choice.

                  You choose which is most relevent