Array out of Objects

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default Array out of Objects

    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?

    rakmaster Guest

  2. Similar Questions and Discussions

    1. How to search into an array of objects?
      Hi, Is there a way to find an item into a array of object without parse each object? Ex: var : myArray : Array = new Array( {label : "cup",...
    2. Array of objects copy
      I have an array of objects, lets call it 'myArrayofObjects' I need to copy the information from this array onto another array because it seems that...
    3. Custom objects in an array
      I have tried to store instances of a custom class in an array. When I retrieve the object actionScript seems to have forgotten what type of object...
    4. array of objects
      I currently have a number of buttons, which have image icons and when clicked, will display th associated image in a large viewing fram I would...
    5. What is this objects name in the array?!
      I have this code sniplet.. function dragalong() { this.startDrag(); } function dropper() { this.stopDrag(); }
  3. #2

    Default Re: Array out of Objects

    check the [url]http://livedocs.adobe.com/flex/3/langref/index.html?migration.html[/url].

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

    if (n is Button) {
    Craig Grummitt Guest

  4. #3

    Default Re: Array out of Objects

    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:

    var lowState:Boolean = false;
    var buttons:Array = [Btn1,Btn2,Btn3];
    var lowLabels:Array = ['label 1','label2','label3'];
    var highLabels:Array = ['LABEL 1','LABEL 2','LABEL 3'];

    function changeLables():void {
    var useArray:Array = new Array();
    if(lowState == false) {
    useArray = lowLabels;
    lowState = true;
    } else {
    useArray = hightLabels;
    lowState = false;
    }
    // test = the name of the movie
    for each(var n:Object in test.getChildren()) {
    if(n is Button) {
    for(var i:int=0;i<buttons.length;i++) {
    if(n.id == buttons[i]) {
    n.label = useArray[i];
    }
    }
    }
    }
    <mx:Button id="Btn1" label="Label 1" />
    <mx:Button id="Btn2" label="Label 2" />
    <mx:Button id="Btn3" label="Label 3" />



    rakmaster Guest

  5. #4

    Default Re: Array out of Objects

    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().

    Craig Grummitt Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139