体验AS3.0(六)

      Flash 2006-2-14 13:41:00
到现在为止,在我们的程序中仅用到了MovieClip,你也许会问:没有了MovieClip.attachMovie 和 MovieClip.createEmptyMovieClip方法,那如何来用AS建立一个MovieClip呢?首先,我们需要用new方法新建一个MovieClip对象,然后把这个MovieClip对象用addChild方法添加进来。下面,我们这个例子生成一个10x10 的表格。
//TEST5.as
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.
我们欣喜地看到,在一个AS文件中建立多个类已经成为可能,AS越来越象JAVA了。
标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}
深度XP 雨林木风XP WinXP下载 世界之窗 深度系统 雨林木风 Ghost ghost系统盘 XP下载