-
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
-
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)
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|