A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [HELP] How to use getDefinitionByName?

  1. #1
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590

    [HELP] How to use getDefinitionByName?

    What I'm essentially trying to do is turn movieclips into spritesheets of themselves, showing all positions of their rotations. I can do this for one MC, but I'm having trouble scaling it up to work on multiple ones.

    Here's (the top of) my code:

    PHP Code:
    import flash.utils.getDefinitionByName;

    var 
    i:int 0;

    var 
    myMCs:Array = ["Test""Test2"];

    var 
    c:MovieClip;

    for (
    i=0i<myMCs.lengthi++) {
        
    getDefinitionByName(myMCs[i]) as MovieClip;
        
    addChild(new c());

    The problem appears to be with the line addChild(new c());.

    It should, in theory, take the list of classes inside myMCs and create an instance of each of those classes.

    In other words, I want to dynamically add movie clip instances of Test and Test2 (plus any other ones I add later) to the displayList.

    The error I get when I try to compile (btw this is in the Flash authoring environment) is:

    1180: Call to a possibly undefined method c.
    http://www.birchlabs.co.uk/
    You know you want to.

  2. #2
    Member
    Join Date
    Sep 2008
    Posts
    95
    Where are your Test and Test2?

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    I think you actually should type c as a Class, not as a MovieClip...not sure this will work, but try:

    Code:
    import flash.utils.getDefinitionByName;
    
    var i:int = 0;
    
    var myMCs:Array = ["Test", "Test2"];
    
    var c:Class;
    
    for (i=0; i<myMCs.length; i++) {
        c = getDefinitionByName(myMCs[i]) as Class;
        var d:MovieClip = new c() as MovieClip;
        addChild(d);
    }

  4. #4
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Thanks Josh, that worked!
    http://www.birchlabs.co.uk/
    You know you want to.

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