3 Replies Latest reply on May 12, 2008 8:18 PM by Craig Grummitt

    Array out of Objects

    rakmaster
      Back in the old days of Flash, I was able to walk through all of the objects on the stage, and filter them by the type of object. I could then detect the id of the given object type and make a match.

      Now, in Flex, I'm completely lost. All I want to do is walk through all of the objects on the stage, determine which ones are a particular type of Object, then match that list of Objects against a known value:
      for each(var n:Object in thisApplication) {
      if(n instanceof 'Button') {
      if(n.id == "myCheckValue") {
      doSomethingToN();
      }
      }
      }

      Is this possible?
        • 1. Array out of Objects
          Craig Grummitt Level 3
          your for loop should go through thisApplication.getChildren()

          also, check the actionscript 3 migration page.

          it is advised to use 'is' rather than 'instanceof' eg.

          if (n is Button) {
          • 2. Array out of Objects
            rakmaster Level 1
            Okay, but what is thisApplication? In Flash I would write:

            for each(n in _root) {
            if(n instanceof 'movieclip') {
            functiontoDo();
            }
            }

            what is the equivalent of _root? If I try to use for each(var n:Object in test.getChildren()) where test is anything; the name of the file, the id of the mx:Canvas that holds the elements I'm trying to address, or even a variable that is assigned the value of any of the above, all I get is an error message that says "Call to a possibly undefined method getChildren through a reference with static type Class." Here's what I'm trying to do:


            <mx:Button id="Btn1" label="Label 1" />
            <mx:Button id="Btn2" label="Label 2" />
            <mx:Button id="Btn3" label="Label 3" />

            • 3. Re: Array out of Objects
              Craig Grummitt Level 3
              rakmaster i only called the object that you wanted to extract the children of 'thisApplication' coz that's what you called it. you can call the getChildren method on any Container. As the main Application class is a container, you can call it on that if you like. so if you are calling this script from the Application class, it would be as simple as calling this.getChildren().