actionscript 3 - Get an array of specific added children -
i'm using following array add children stage:
for(var i=0;i<6;i++) { var acherry=new ccherry() acherry.y=10 acherry.x=10+100*i stage.addchild(acherry) } now want modify each cherry based on array. this:
var cherryletter:array=[1,0,0,0,0,0] for(i=0;i<6;++) { if(cherryletter[i]) stage.getchildbyname("acherry")[i].y+=90 } clearly stage.getchildbyname("acherry")[i] isn't correct, coming javascript makes sense me , should accurately portray i'm trying achieve guys reading this. so, how this? being getting array of children added stage under name or class (so array of ccherry work too, if necessary), using them in way similar above loop.
here recommendation how code might look, based on desire use getchildbyname() find instances of ccherry class. please note i've changed class name cherry in example (which recommend, since capitalizing class names as3 convention). also, it's practice end statements semi-colons. while it's optional, there cases omitting semi-colon can produce difficult track down runtime bugs, recommend getting int habit of using them. recommend including type in variable declarations, shown var acherry:cherry, example.
var i:int; for(i=0; i<6; ++i) { var acherry:cherry=new cherry(); // note, it's recommendation rename ccherry class cherry (convention) acherry.y=10; acherry.x=10+100*i; acherry.name = "acherry" + string(i); // string() cast clarity only, not necessary stage.addchild(acherry); } and
var cherryletter:array=[1,0,0,0,0,0]; for(i=0; i<6; ++i) { var cherry:cherry = stage.getchildbyname("acherry" + string(i)) cherry; if(cherry && cherryletter[i]) cherry.y += 90; }
Comments
Post a Comment