如何在AS3中克隆一个对象



我是AS3的新手,但是我正在制作的游戏需要使用Clones。我将如何制作它们(我知道这涉及使用孩子的东西,但我不知道如何制作它们(?我还需要制作一个将其位置设置为屏幕上随机位置的函数,我该怎么做?我不确定如何在不移动所有50个位置的情况下参考克隆的X和Y位置。谢谢

制作任何东西的克隆的最佳方法是将AS3类分配给库项目(假设您将class something nater命名为(,然后将其实例化 new 操作员,并使用 addchild(...( method。添加到显示列表。

import SomeThing;
// Lets create a list to keep things.
var things:Vector.<SomeThing> = new Vector.<SomeThing>;
function addThing():SomeThing
{
    // Create.
    var result:SomeThing = new SomeThing;
    // Put it to a list for further reference.
    things.push(result);
    // Add it to display list.
    addChild(result);
    return result;
}
// Create one thing.
// This one will go to (0,0) coordinates.
addThing();
// You can create several things.
for (var i:int = 0; i < 100; i++)
{
    var aThing:SomeThing = addThing();
    aThing.x = 100 + 200 * Math.random();
    aThing.y = 100 + 100 * Math.random();
}
// Now you can address things via list access.
things[49].x = 50;
things[49].y = 50;