动作脚本3:添加矢量图作为孩子,图纸不会显示

时间:2013-05-16 17:59:17

标签: actionscript vector sprite addchild

我对动作片有点新意,所以拜托,请耐心等待。我正在尝试将矢量绘制为精灵,并将它们作为子项添加到父“容器”下。当我列出'容器'下的子项名称(使用跟踪)时,输出清楚地显示添加的Sprite的每个实例。当我测试电影时,我看不到任何精灵。当我删除'test = new Sprite();'从循环中改变'var test:Sprite;' 'var test:Sprite = new Sprite();',我可以看到Sprites。我的目标是创建Sprite的单独实例,以便我可以单独访问它们,但我看不到它们。任何帮助将不胜感激!

import flash.display.Sprite;
var container:Sprite = new Sprite();
container.x = 0;
container.y = 0;
addChild(container);
var test:Sprite;
var i:int = 0;

while (i < 10) {
    test = new Sprite();
    test.graphics.drawRect(0 + i*10,0 + i*10,0 + i*10,0 + i*10);
    test.graphics.beginFill(0x000000);
    test.graphics.endFill();
    test.name = "test" + i;
    container.addChild(test);
    i++;
}
for (var k:int = 0; k < container.numChildren; k++) {
    trace(container.getChildAt(k).name);
}

1 个答案:

答案 0 :(得分:0)

import flash.display.Sprite;
var container:Sprite = new Sprite();
container.x = 0;
container.y = 0;
addChild(container);
var test:Sprite;
var i:int = 0;

while (i < 10) {
    test = new Sprite();
    test.graphics.beginFill(0x000000);
    test.graphics.drawRect(0 + i*10,0 + i*10,0 + i*10,0 + i*10);
    test.name = "test" + i;
    test.x = 200;
    test.y = 100;
    container.addChild(test);
    i++;
}
for (var k:int = 0; k < container.numChildren; k++) {
    trace(container.getChildAt(k).name);
}

在绘制rect之前开始填充,我认为你也需要设置x和y。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Sprite.html