5 Replies Latest reply on Jul 25, 2006 9:00 AM by Newsgroup_User

    'watch' a MC

    Level 7
      Hi,
      i'm looking for a way to 'watch' a property of a MC like the 'watch' funtion
      of objects.
      in other words, i want a function to be called every time the visibility of
      a certain MC changes.
      what's the most simple way to do that?
      thanks,
      eRez


        • 1. Re: 'watch' a MC
          blemmo Level 1
          Have you tried to use watch? MCs are objects as well, so it should be possible to use watch on them as on every other object.

          cheers,
          blemmo
          • 2. Re: 'watch' a MC
            Level 7
            thanks, but yes - i have tried adding this line to my code -
            '_mc.watch("_visible",myFunction);' but without success (and in case u're
            wandering i've also tried '_mc.watch("visible",myFunction);').
            any other suggestions?
            eRez

            "blemmo" <webforumsuser@macromedia.com> wrote in message
            news:ea4t9c$lbo$1@forums.macromedia.com...
            > Have you tried to use watch? MCs are objects as well, so it should be
            > possible to use watch on them as on every other object.
            >
            > cheers,
            > blemmo


            • 3. Re: 'watch' a MC
              Level 7
              eRez,

              > thanks, but yes - i have tried adding this line to my
              > code - '_mc.watch("_visible",myFunction);' but
              > without success (and in case u're wandering i've also
              > tried '_mc.watch("visible",myFunction);').
              > any other suggestions?

              From the documentation (Object.watch() method) ...

              <quote>
              The Object.watch() method cannot watch getter/setter properties.
              Getter/setter properties operate through lazy evaluation-- the value of the
              property is not determined until the property is actually queried. ...
              Generally, predefined ActionScript properties, such as _x, _y, _width, and
              _height, are getter/setter properties and cannot be watched with
              Object.watch().
              </quote>

              My hunch, in this case, is that you'll have to extend MovieClip with
              your own class and dispatch an event when the _visible property is set. But
              that seems like overkill. Why don't you just dispatch an event from the
              code that toggles the movie clip's _visible property?


              David
              stiller (at) quip (dot) net
              Dev essays: http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: 'watch' a MC
                Level 7

                >
                > Why don't you just dispatch an event from the code that toggles the movie
                > clip's _visible property?

                had i had only one place in my code that toogles that clip visibility of
                course it would have been a whole lot more simple. i'm working on a complex
                project some other programmer began before me, and i'm probably not even
                aware of all the places the visibility changes - that's why i looking for
                some 'watch' replacement.
                i was thinking of event dispatcher or listener of some sort, but i'm not
                very familiar with this method, so any simple example will do.

                thanks,
                eRez


                • 5. Re: 'watch' a MC
                  Level 7
                  eRez,

                  > had i had only one place in my code that toogles that
                  > clip visibility of course it would have been a whole lot
                  > more simple.

                  Gotcha.

                  > i'm working on a complex project some other programmer
                  > began before me, and i'm probably not even aware of
                  > all the places the visibility changes - that's why i looking
                  > for some 'watch' replacement.

                  Though not ideal, I suppose you could constantly check that property in
                  something like a MovieClip.onEnterFrame or setInterval() loop.

                  > i was thinking of event dispatcher or listener of some
                  > sort, but i'm not very familiar with this method, so any
                  > simple example will do.

                  http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster
                  http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher


                  David
                  stiller (at) quip (dot) net
                  Dev essays: http://www.quip.net/blog/
                  "Luck is the residue of good design."