In Actionscript 3 I could add a method to an object dynamically.
like to below code
var s:Sprite = new Sprite()
var f:Function = function(){this.graphic.clear()}
s.clean = f
could I create another Sprite instance with the clean function from s ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is possible using the prototype of Sprite :
Of course this adds clean to all the instances of Sprite you create, if that’s not what you want you could just create a function to create sprites and use that.
If you don’t want to alter the Sprite class your other option is inheritance and adding the clean method to this new class :