A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Instantiate a Class picked from a Class Array

Hybrid View

  1. #1
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Are you sure that the objects in your class array are Classes? Does range return a single random integer in the specified range?

    If both of those are true, it should work.

    I suspect you have something other than classes in your array (such as String), causing objClass to be null.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    This example will give you the error you got, because Green is a string:

    var myArray:Array = new Array("Green");
    var objClass:Class = myArray[0] as Class;
    var objisplayObjectContainer = new objClass() as DisplayObjectContainer;
    addChild(obj);

    Changing the first line will correct the mistake:
    var myArray:Array = new Array(Green);

    Probably the array members are all strings.
    - The right of the People to create Flash movies shall not be infringed. -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center