Subscribe: Comments on: Accessing private class members in AS3
Added By: Feedage Forager Feedage Grade B rated
Language: English
access members  access  approach  defined  dynamic  eric hey  eric  members defined  members  method  methods  private members  private 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Comments on: Accessing private class members in AS3

Comments on: Accessing private class members in AS3

Thoughts on Modern Web Development ...

Last Build Date: Fri, 16 Dec 2016 03:19:26 +0000


By: Denis

Fri, 11 Jul 2008 19:34:09 +0000

Hi Eric, Is it possible to reflectively call functions in AS3 as well or is this confined to modifying member variables? If possible, how would one go about doing this?

By: eric

Wed, 19 Mar 2008 15:33:14 +0000

Hey Rodney, This approach is intended to modify members of sealed classes, not add members to dynamic classes. There is a big difference: This approach does not add or remove members to the prototype object of a Class, rather it makes assignments to sealed private members defined on the traits object of a Class which would otherwise be inaccessible. - Eric

By: eric

Wed, 19 Mar 2008 15:26:35 +0000

Hey Stefan, This approach is intended as an alternative to exposing setters. It is typically used for automation APIs in which you may need to modify specific properties at runtime but you do not want to expose those members publicly. The properties which are to be modified would only be known within the API that modifies them. I also recommend using a custom namespace in order to help prevent potential misuse. - Eric

By: Stefan Richter

Thu, 13 Mar 2008 15:19:57 +0000

Hi Eric, sorry if I missing something here but if the methods need to be defined inside the actual class (in your example the User class) then why would or should this approach be used? Would it not be easier to simple add some setters? Cheers Stefan

By: Rodney Pillay

Wed, 12 Mar 2008 06:46:22 +0000

Hi if you define your class as dynamic "dynamic public class.." , the you can access private methods and attributes using dynamic addressing like in AS2 ... If you conclude during design time that the class you are going to write needs its private methods and attributes accessed then you should be using dynamic, thats just my view.

By: eric

Tue, 11 Mar 2008 17:58:12 +0000

Hey Paul, The error you are getting is to be expected as methods declared outside of the class which defines the private members will never be able to access those members. The method which modifies private members must be defined in the class in which the members are defined, otherwise the method would not have access to those members. This applies to all languages, not just AS3. Think of it like this, private members are only accessible from within the class in which they are defined, therefore if the method which modifies these members is also defined in the same class then that method has access to those members as well. Hope that is clear. Thanks, Eric

By: Paul

Tue, 11 Mar 2008 17:24:20 +0000

In AS3 this only works if the function is declared in the same class in which the private member is declared. Otherwise you'll get a runtime exception. I thought that by setting a handful of compiler flags (-es=true -as3=false -strict=false) you could get around this but I just tested it and the exception still occurs.