简体   繁体   English

类名数组AS3

[英]Array of Class Names AS3

I've got several movieclips in my FLA library with classnames applied. 我的FLA库中有几个应用了类名的电影剪辑。 In my AS package file, I've got an array of those classnames. 在我的AS包文件中,我有一个这些类名的数组。 What I'd like to do is display the movieclips on stage as follows: 我想做的是在舞台上如下显示影片剪辑:

  • Upon SWF load, Array[0] displays 加载SWF时,显示Array [0]
  • When NEXT button is clicked, add 1 to array, then display 单击下一步按钮后,将1加到数组中,然后显示
  • When PREV button is clicked, subtract 1 from array, then display 单击PREV按钮时,从数组中减去1,然后显示

Total n00b question, I'm sure. 总共n00b个问题,我确定。 I understand the basics, but calling the classnames has me confused. 我了解基本知识,但是调用类名让我感到困惑。 Any help would be appreciated! 任何帮助,将不胜感激!

If you have an array of class names, you'll first have to retrieve the class definition before you can dynamically instantiate it. 如果您有一个类名数组,则必须首先检索该类定义,然后才能动态实例化它。 You can use the getDefinitionByName() method for that. 您可以为此使用getDefinitionByName()方法。

var clazz:Class = getDefinitionByName(myClassName) as Class;
var instance:MovieClip = new clazz();

If you have an array of classes, you can instantiate a class like this: 如果有一个类数组,可以实例化一个这样的类:

var classArray:Array = [ Class1, Class2, Class3 ];
// instantiate the first class in the array at index 0
var instance:MovieClip = new classArray[0]();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM