A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: New instance of object from within a class

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    7

    New instance of object from within a class

    This is probably really simple, but I can't figure it out.

    If I pass a MovieClip through as an argument in the constructor for a class I am writing, how do I create a new instance of that MovieClip from within the class?

    The MovieClip has a custom class name that is unknown to the class I am writing, it is simply passed through as a MovieClip.

    I tried:
    Code:
    _class = Object(mc).constructor;
    _mcArray[i] = new _class;
    But it doesn't work. I am new to Flash and AS3 so it's probably really simple.

    Thanks

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Interesting approach - I never thought of instantiating directly off of another object's constructor. You should be able to get that working like so:

    PHP Code:
    _mcArray[i] = new mc.constructor(); 
    Please use [php] or [code] tags, and mark your threads resolved 8)

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That will only work if the class has a no-argument constructor. Since Thomas didn't tell us whether he's getting any error messages or what they are, we may never know.

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    7
    Thanks for the replies, fortunately I got he issue resolved myself. The code I posted does work, it was something else that threw up an error. Flash is so vague and cryptic with it's error messsages, it kills me

    The class I am referencing has a no-argument constructor. I hadn't thought about it. Is there a way to copy a current MovieClip to an new instance instead of constructing a new instance?

    Thanks again
    Last edited by thomashw; 12-14-2009 at 06:35 AM.

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