Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:44:00+00:00 2026-06-12T20:44:00+00:00

In Actionscript 3 I could add a method to an object dynamically. like to

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:44:01+00:00Added an answer on June 12, 2026 at 8:44 pm

    It is possible using the prototype of Sprite :

    Sprite.prototype.clean = function():void { trace("works"); }
    var s1:Sprite = new Sprite();
    var s2:Sprite = new Sprite();
    s1["clean"]();
    s2["clean"]();
    

    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.

    function createSprite():Sprite
    {
       var s:Sprite = new Sprite();
       var f:Function = function(){this.graphic.clear()}
       s.clean = f ;
       return s;
    }
    

    If you don’t want to alter the Sprite class your other option is inheritance and adding the clean method to this new class :

    public class MySprite extends Sprite
    {
       public function clean():void
       {
          this.graphic.clear();
       }
    }
    
    var s1:MySprite = new MySprite();
    s1.clean();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Flash ActionScript myData = new LoadVars(); myData.onLoad = function() { myText_txt.text = this.myVariable; };
In Actionscript, the Unix timestamp in milliseconds is obtainable like this: public static function
In Actionscript you can have global variables like this: var number : Number =
Could you tell how the actionscript code would look like for such a job?
Just wondering if anyone could help me with this. I'm new to actionscript, and
my apologies if this question doesn't make much sense, but I'm new(ish) to Actionscript,
Say I have an object var my_obj = new Object(); my_obj['key'] = value; Is
This is not necessarily specific to ActionScript 3 but I could not think off
In JavaScript I can take anyOldObject and add anyOldObject[anyOldProperty]=Test . I could do this
I could call a javascript global function from ActionScript using ExternalInterface. Can I somehow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.