Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 使用扩展的movieclip_Flash - Fatal编程技术网

Flash 使用扩展的movieclip

Flash 使用扩展的movieclip,flash,Flash,我创建了一个movieclip,并使用用户定义的类对其进行了扩展。现在,如果我想使用该电影剪辑并使用该类中的属性,我该怎么做呢 //declare a variable of appropriate type and initialize it var myClip:YourClipName = new YourClipName(); //now you can use myClip as if it were a movie clip variable addChild(myClip); my

我创建了一个movieclip,并使用用户定义的类对其进行了扩展。现在,如果我想使用该电影剪辑并使用该类中的属性,我该怎么做呢

//declare a variable of appropriate type and initialize it
var myClip:YourClipName = new YourClipName();
//now you can use myClip as if it were a movie clip variable
addChild(myClip);
myClip.x = 10;
//you can also access your custom properties/method with myClip
myClip.myAweSomeMethod(42, "Tadaa");
myClip.prop1 = "Some Value";
阵列的更新:

//initialize
//n : Total_number_required
public var clips:Array = [];
for(var i:Number = 0; i < n; i++)
{
  var clip:YourType = new YourType();
  clip.x = 10 * i;
  clip.y = 20 * i;
  clips.push(clip);
}
//somewhere else in the code
//to get the clip at the kth index
var clip:YourType = YourType(clips[k]);
clip.x = 100;
clip.rotation = 90;
//初始化
//n:需要的总数量
公共变量剪辑:数组=[];
对于(变量i:Number=0;i
@Richard
\ux
在AS2中,而
x
在AS3中。OP没有指定语言版本,所以我使用了AS3(因为我更习惯使用它)。感谢@Amarghosh的回复。我现在面临的问题是,如果我需要创建10个此电影剪辑实例。如何单独引用它们?如果所需的实例数量较少,并且每个实例执行不同的操作,则可以为每个实例声明单独的变量并赋值。如果您要创建很多剪辑,并且所有剪辑都要执行类似的操作(例如,它们将是类似列表的结构的成员),那么您可以声明一个数组并将实例存储到该数组中。您还可以为它们命名(例如myClip.name=“something”)。然后,如果已将它们添加到DisplayObject容器中,只要引用正确的父容器,就可以继续。someParentContainer.getChildByName(“某物”);而且它会返回它。@所有人都要小心使用
getChildByName
,尤其是当舞台上有很多剪辑时。如果您意外地将相同的名称分配给多个同级,则该方法将返回显示列表中的第一个名称(而不是在分配重复名称时引发错误)