3 Replies Latest reply on Apr 19, 2006 2:42 AM by Peter Lorent

    watch() problem

    asidfree
      Hello,

      I have a global value (shown below as buildingClicked) and I am just having problems getting a watch to work in the parent .swf.

      I have a .swf being loaded in, and I have that .swf change the global value in the parent .swf. When I call something like, "_global.buildingClicked=something" from the loaded .swf, it doesn't envoke the watch.

      If anyone could give it a look and give me some advice that would be excellent.

      ~asidfree
        • 1. Re: watch() problem
          Peter Lorent Level 2
          >>testBtn.onRelease = function() {
          _global.buildingClicked = "sample string";
          }
          The global var is already declared. Use:
          testBtn.onRelease = function() {
          buildingClicked = "sample string";
          }
          But:
          >>trace("buildingClicked: " + buildingClicked)
          That won't work. Only after the return statement the new value is set. You can do:
          trace("buildingClicked: " + newValue)
          • 2. Re: watch() problem
            asidfree Level 1
            Thanks for the reply LuigiL,

            I did change the variable to trace the newVal. It was a helpful insight over somthing I missed. Thanks.

            I am pretty sure that when I specify, "_global.buildingClicked" I am referencing the _global value in the parent clip, not declaring a new variable in the child. The Macromedia liveDocs page state, " ...you could access the global-scoped variable if you prefix it with _global." Here is a link: Global Variables.

            None-the-less, I tried your advice (taking out the " _global.") and got the following error. I'm pretty sure you're on to something though, I just don't understand where you're taking me.

            Here's some more explination (walkthrough): Parent (swf) loads in child (swf). Parent contains global variable, watches it, and calls a function that resides in itself when changed. The child modify's the global variable in it's parent. I have checked to be sure that the child is changing the global. It does appear to be changing the variable, but it doesn't envoke the watch at all for some reason.

            Thanks for the help,

            • 3. Re: watch() problem
              Peter Lorent Level 2
              Sure you can access the _global. But the watch() won't work...
              It does however if you use:
              _level0.buildingClicked="sample string";

              But, you are using a class or classes. If you want to elaborate on this, post the class(es) or at least the relevant code.