Thanks. I'm actually not setting to an explicit value, just left that code out as it is not important to the question. Do you know the design reason for not being able to override the variable with implicit (although explicit after compilation) getter/setter?
One of the things I love about ActionScript is that we are not forced to create boiler plate code for getter/setter for each variable. I come from the Java world and we need to do that. I find great power in just making the property public. Then any other class that needs to get or set can simply do something like myObj.foo = bar. If later myObj decides that the setter should do something else, simply tweak the code and add the setter. The other classes code does not need to change, it still just does myObj.foo = bar. In Java, this is not the case, you'd have to do myObj.setFoo(bar). I love the fact that we don't have to litter our code with boilerplate getter/setter and only implement if we need more processing during a get or set. With the way it works with not being able to override really removes this ability. I know that we have code generators for creating getter/setters and we can collapse the code in the IDE, but that still has a bunch of dumb code that needs to be there. So if you know the design reason, I'd love to know what it is. Thanks, Dale From: [email protected] [mailto:[email protected]] On Behalf Of Darin Kohles Sent: Tuesday, December 07, 2010 4:20 PM To: [email protected] Subject: Re: [AFFUG Discuss] Needs override, doesn't allow override Public properties have implicit getter/setter behavior, but as you found you can not override an implicit function with an explicit override (yes, once compiled their will be an actual explicit function if you look at the source, but this doesn't help you during compilation). If Class A is always used as a super class, have your colleague change it from public to protected. If however, you really want to add custom code/functionality for the retrieval of the variable that is different than what is supplied by the underlying public property (in your example it looks like you are trying to force it to return a set value regardless of what the actual value is). I'd suggest playing with BindingUtils (assuming the public property iAmPublic is [Bindable]): var cw:ChangeWatcher = BindingUtils.bindSetter( overrideSet, this, iAmPublic); private function overrideSet( value:int ):void { iAmPublic = 9; } This guarantees that if the property is set, it is set to the value you want, but does not guarantee that the property has a value (or in this case a specific value. You can ensure the property is set by explicitly assigning a vale (then overridden to your desired value) during initialization. On Tue, Dec 7, 2010 at 2:51 PM, Dale Bronk <[email protected]> wrote: I'm sure there is a reason for this, but I don't know it and can't seem to find it googling. I have: ClassA public var iAmPublic : int = 0; ClassB extends ClassA public function get iAmPublic() : int { return 9; } - or - override public function get iAmPublic() : int { return 9; } Both compile error out. Either with I must override the function or invalid override. If I change ClassA to have public function get/set .... it will work fine. I realize that behind the scenes a get/set must be created for me, but it seems to me the compiler should be smart enough to handle this. The big problem is that I'm dealing with a swc that has the property as a public var so I can't override it. Anyone have any ideas? I can go to the person and have them change it to do getter/setter, but doesn't this seem like something that should just work? Thanks, Dale ------------------------------------------------------------- To unsubscribe from this list, simply email the list with unsubscribe in the subject line For more info, see http://www.affug.com Archive @ http://www.mail-archive.com/discussion%40affug.com/ List hosted by http://www.fusionlink.com ------------------------------------------------------------- -- Darin Kohles ------------------------------------------------------------- To unsubscribe from this list, simply email the list with unsubscribe in the subject line For more info, see http://www.affug.com Archive @ http://www.mail-archive.com/discussion%40affug.com/ List hosted by http://www.fusionlink.com -------------------------------------------------------------
