A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: for...in loop in as3 to find MC

  1. #1
    Junior Member
    Join Date
    Aug 2004
    Posts
    15

    for...in loop in as3 to find MC

    I can't quite get this syntax in as3 to work. In as2 I used to just write

    for (all in this){
    if(this[all].findme==true){
    trace(this[all])
    }
    }

    I am trying to find movie clips that have the variable findme=true in them in "this" movie clip.

    How do I do this in as3?

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    what seems to be happening in your code?

    The only thing that AS3 might not like is the lack of the word 'var' inside your parenthasis

    for (var all in this) {
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    recursing the display list is a lot different in AS3... here's a function that's pretty fast if a little messy
    PHP Code:
    function descendants(a){
        var 
    = [], c;
        var 
    = function(e){
            if(
    "numChildren" in e){
                for(var 
    i=0;i<e.numChildren;i++){
                    var 
    e.getChildAt(i);
                    
    b.push(c);
                    
    d(c);
                };
            };
        };
        
    d(a);
        return 
    b;
    }; 
    the semantics and transparency suck - it was just a quick and dirty func i used once a while back... anyhow, call it on "this" and it'll give you an array of all the descendants... the loop through that to find anything with findme... like so
    PHP Code:
    var allchildren:Array = descendants(this);
    for(var 
    i:uint=0;i<allchildren.length;i++)if("findme" in allchildren[i])trace(allchildren[i]); 

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center