简体   繁体   中英

Array of Class Names AS3

I've got several movieclips in my FLA library with classnames applied. In my AS package file, I've got an array of those classnames. What I'd like to do is display the movieclips on stage as follows:

  • Upon SWF load, Array[0] displays
  • When NEXT button is clicked, add 1 to array, then display
  • When PREV button is clicked, subtract 1 from array, then display

Total n00b question, I'm sure. 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.

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]();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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