Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. Dynamic ActionScript > Dynamically Adding New Behavior to an Instan...

15.2. Dynamically Adding New Behavior to an Instance

Having just learned how to create dynamic instance variables, you might wonder whether ActionScript also supports dynamic instance methods—adding a new instance method to a single, specific object without adding it to any other instances of that object's class. In fact, there is no formal means of adding a true instance method to an object dynamically. However, by assigning a function closure to a dynamic instance variable, we can emulate the effect of giving an individual object a new method (for a refresher on the term function closure, see Chapter 5). The following code demonstrates the general approach:

someObject.someDynamicVariable = someFunction;


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint