2007年12月25日 星期二

Create 1,000 Christmas trees

Hey, it is fun to create ONE trees and easy to become 1,000 more!







Demo : http://annwongfresh.googlepages.com/duplicateTree2.html
Source : http://annwongfresh.googlepages.com/duplicateTree2.fla
YouTube : http://www.youtube.com/watch?v=dmLAFsrS7qg


ActionScipt :
for(var i = 1; i<100; i++){

tree_mc.duplicateMovieClip("tree"+i,i);
this["tree"+i]._x =(400-1)*Math.random()+1;
this["tree"+i]._y =(300-1)*Math.random()+1;
}


Explain :

for(var i = 1; i<100; i++){ .... } // duplicate 99times

Math.random() // Method; returns n, where 0 <= n < 1
eg. may have 0, 0.5 , 0.2 ... etc.

tree_mc.duplicateMovieClip("tree"+i,i); // duplicate MovieClip

doucment size is 400w x 300h , so _x and _y should be between them.




YouTube : http://www.youtube.com/annwongfresh
Yahoo Blog : http://hk.myblog.yahoo.com/annwongfresh/







0 Comments: