How to use 'asyncfor' to loop trough all the layers which name contains 'btn_'

  • Hello all,

    I'm sure I've seen something like that before in another tour.
    Even more, I think I've done it myself in the past! But I just can't find how to do it!

    Basically I'd like to do is the following:

    I have several <layers> which names are 'btn_#' (this is btn_1, btn_2, etc...)
    Depends on the tour, sometimes there will be 2, 3, 4 buttons or more. Who knows.
    I'd like to hide all the buttons at the same time, and this looks like a perfect job for 'asyncfor'

    Code
    for(set(i,0), i LT 10, inc(i),
        	txtadd(btn_name,btn_,get(i),_icon);
        	tween(layer[get(btn_name)].alpha,0,.5,easeoutquad);
        	);

    Yes that works but it feels like I'm cutting corners. You know, loop 10 times because I know I'll never put more than 10 of those buttons.

    There must be a better way, where for example, the loop only applies to the layers which name contains 'btn_'
    Is this possible?

    Thanks

  • I juts found a way to do it by using the <layer> style attribute. Here it is:

    Code
    for(set(i,0), i LT layer.count, inc(i),
       	      	copy(lr, layer[get(i)]);
       	  	    if(lr.style === color_btn_style,
     	    	         	txtadd(color_btn_name,color_btn_,get(i));
     	    	     	    tween(layer[get(color_btn_name)].alpha,0,.5,easeoutquad);
       	      	);
        	);

    Sorry about the formatting. It never works right for me when I post code in the forum.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!