-
1. Re: How do you addChild from a class?
kglad Jun 15, 2011 6:54 PM (in response to xTLS)your class instance must extend the displayobject. so yes, extending sprite or movieclip would work.
or you can pass a displayobject reference to your class and apply the addChild() method to that reference.
-
2. Re: How do you addChild from a class?
relaxatraja Jun 16, 2011 12:28 AM (in response to xTLS)A sample document class:
package {
import flash.display.MovieClip;
public class test extends MovieClip {
public function test() {
// constructor code
var test:MovieClip=new t();
addChild(test);
}
}
}t is the movieclip which have t as a class name in the library.
-
3. Re: How do you addChild from a class?
xTLS Jun 22, 2011 4:32 PM (in response to relaxatraja)All right, thank you, that's very helpful.
Another related question: is it possible to have a class that extends MovieClip but uses a specific graphic? Er, to better explain, say I have in my library:
A MovieClip named MCBox
A Class named ClassBox which Extends MovieClip
Is it possible to make it so if I make a new instance of ClassBox and add it to the stage, it uses the MCBox graphic? And I can just change the x,y, etc like normal (i.e. ClassBox.x=25)? Or would I have to make the MCBox a property, and refer to it like "ClassBox.image.x=25" or similarly?
Really appreciate the help! Sorry for not responding sooner, I've been very busy.
-
4. Re: How do you addChild from a class?
kglad Jun 22, 2011 4:43 PM (in response to xTLS)right click your library movieclip, tick export for actionscript and assign a class (eg, ClassBox) that matches your class file. when you create an instance of ClassBox:
var cb:ClassBox=new ClassBox();
the constructor in your class file will execute.
and yes, you can use
cb.x=
cb.y=
where you create your cb instance or you can assign those properties in your class file (or do both).
-
5. Re: How do you addChild from a class?
xTLS Jun 22, 2011 6:12 PM (in response to kglad)Oooh, I never knew that. Thanks!
EDIT: The constructor in my custom class file is supposed to take an argument, but if I follow the format var cb:ClassBox=new ClassBox(argument), I get the wrong number of arguments (expected 0) error, so I don't think it's calling the correct constructor. Any thoughts?
-
6. Re: How do you addChild from a class?
kglad Jun 22, 2011 7:31 PM (in response to xTLS)your class isn't being used because of a typo or path issue.
show your class code from package{ to the end of your constructor.
-
7. Re: How do you addChild from a class?
xTLS Jul 17, 2011 4:53 PM (in response to kglad)There's no typo or path issue, if I instance the custom class separately it works fine. Could you explain in more detail how this is supposed to work?
edit: Never mind, I didn't realize from your explanation that the Class has to have the same name as the MovieClip >_< . It didn't complain when I tied it to a class with a different name, and it worked if I didn't try to pass it any parameters, so I was confused.
-
8. Re: How do you addChild from a class?
kglad Jul 17, 2011 11:59 PM (in response to xTLS)if this issue is resolved, please mark helpful/correct responses, if there are any.




