Until now, we always used one MovieClip only. If you know ActionScript 2, you may wonder, how to create MovieClips without MovieClip.attachMovie or MovieClip.createEmptyMovieClip. In contrast to Actionscript 2, where the tree of MovieClips was build implicitely by the aforementioned factory methods, now we have to create the tree more explicitely. You start with creating a MovieClip using "new" and then insert this clip into the displaylist by using addChild. I'm sure, programmers from other language camps will understand this much easier than the old way. Our example creates a 10x10 grid of MovieClips.
package {
import flash.util.trace;
import flash.display.MovieClip;
public class Test extends MovieClip {
public function Test() {
for( var i:int = 0; i<10; i++){
for( var j:int=0; j<10; j++){
var mc:MovieClip = new Test2(i,j);
this.addChild( mc);
}
}
}
}
private class Test2 extends MovieClip {
public function Test2(i:int, j:int){
graphics.beginFill(0xff0000);
graphics.drawRect(0, 0, 10, 10);
graphics.endFill();
x = i * 11;
y = j * 11;
}
}
}
Also nice to see, that multiple classes per file are possible now. This is particular nice for private classes, which are used inside a package only.
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}