actionscript 3 - Adding a new child movieclip -
i trying cube movieclip create instance of , add stage @ coordinates right next previous one. can't keep adding more children/ can't figure out how access childs coords. attempted add new movieclip:mc every iteration of loop vertical , horizontal counting 50 every time , then,on different thought process, tried adding new child every loop don't know how access childs properties. appreciated. thank you.
var countv:int=600; var counth:int=600; stage.addchild(havenalpha); var movehorv:boolean=true; var mc:movieclip = new haven_expand(); for(var i:int=0; i<=5; i++){ if(movehorv == false){ stage.addchild(mc); counth=counth-50; mc.x= counth; movehorv=true; }else if(movehorv == true){ stage.addchild(mc); countv=countv-50; mc.y=countv; movehorv=false; } trace(countv,counth,movehorv,i); stage.addchild(new haven_expand()) stage.addchildat(new haven_expand(),counth); }
in object oriented languages, variables pointers actual objects. changing stored in variable, doesn't make stored there go away.
to end, can make 1 var
store each new object created every iteration. so:
stage.addchild(havenalpha); //this var store clip preivous iteration, we'll start off first item var prevclip:movieclip = new haven_expand(); prevclip.x = 600; prevclip.y = 600; stage.addchild(prevclip); var curclip:movieclip; //used in loop below hold current iterations item for(var i:int=0; i<=5; i++){ curclip = new haven_expand();//create new clip stage.addchild(curclip); //add stage if(i % 2){ // % (modulous) gives remainder of division, false (0) every other time curclip.x = prevclip.x - curclip.width; //place new clip left of last iteration's clip curclip.y = prevclip.y; }else if(movehorv == true){ curclip.y = prevclip.y - curclip.height; //place new clip on top of last iteration's clip curclip.x = prevclip.x; } prevclip = curclip; }
i'm not sure though if x/y math desire. make them distribute in diagonal fashion. wanting horizontal rows? can update show if desired.
Comments
Post a Comment