> I'm still getting my head around the whole
> 'public get/set variableName():blah' construct
 
It's the reason that Flash and Flex APIs can be property-centric instead
of method-centric. You can make lots of things happen simply by
assigning new values to properties, because the setter method can have
all kinds of interesting side effects. In Flex, the typical thing that
happens is that the setter of a property (at least on visual components)
calls various invalidation methods which cause the component to undergo
relayout via the LayoutManager. Setters also generally dispatch various
(undocumented) event to cause binding expressions to re-evaluate.
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Peter Connolly
Sent: Friday, August 24, 2007 3:46 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Overriding getters/setters getting compile
error



That makes sense.  I'm still getting my head around the whole 'public
get/set variableName():blah' construct, which doesn't exist in
Java-land.

pc


On 8/24/07, Doug Lowder < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote: 

        Please pardon my jumping in here, but I think it may just be
more a 
        case of duplicate names than scoping issues. The compiler
identifies 
        a getter function by its name, and the same with a variable. If
you 
        have both a getter and a variable named "widget", how would the 
        compiler be able to tell them apart and know when you wanted
just the 
        variable as opposed to executing the getter function? Prefixing 
        the "_" to the variable name is typical convention for mking the

        variable and getter/setter distinguishable from each other 
        (e.g., "_widget" is the variable, "widget" is the
getter/setter).
        
        Doug
        
        --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> , "Peter Connolly"
<[EMAIL PROTECTED]> 
        wrote:
        >
        > Thanks Tony, although I must admit that I don't understand why
this 
        now
        > works. Why can't the variable and the getter/setter methods be
in 
        the same
        > scope? I don't remember reading anything about that kind of 
        restriction...
        > 
        > 
        

        > On 8/23/07, Tony Alves <[EMAIL PROTECTED]> wrote:
        > >
        > > Your private variable and getter/setter are in the same
scope.
        > > try:
        > > private var _widget:String;
        > > override public function get widget():String {
        > > return _widget;
        > > }
        > > override public function set widget(value:String):void {
        > > _widget = value;
        > > }
        > > Peter Connolly wrote:
        > > >
        > > > I get the following compiler errors:
        > > >
        > > > 1021: Duplicate function definition Base.as <
http://Base.as <http://Base.as> >
        > > > line 11
        > > > 1021: Duplicate function definition Base.as <
http://Base.as <http://Base.as> >
        > > > line 14
        > > > 1023: Incompatible override Base.as < http://Base.as
<http://Base.as> >
        > > > line 11
        > > > 1023: Incompatible override Base.as < http://Base.as
<http://Base.as> >
        > > > line 14
        > > >
        > > > If my parent class is:
        > > >
        > > > package
        > > > {
        > > > public class Base
        > > > {
        > > > private var widget:String;
        > > >
        > > > public function Base(value:String = "base-level widget") {
        > > > trace("'Base.as <http://Base.as <http://Base.as> >' -
value of widget is: " 
        > > > + this.widget);
        > > > }
        > > >
        > > > public function get widget():String {
        > > > return this.widget;
        > > > }
        > > > public function set widget(value:String):void {
        > > > this.widget = value;
        > > > }
        > > > }
        > > > }
        > > >
        > > > and the class with overriden getters/setters is:
        > > >
        > > > package
        > > > {
        > > > public class OverridenClass extends Base
        > > > {
        > > > public function OverridenClass(value:String = "overriden
        > > > widget value") {
        > > > super(value);
        > > > trace("value of widget is: " + widget);
        > > > }
        > > >
        > > > override public function get widget():String {
        > > > return widget;
        > > > }
        > > > override public function set widget(value:String):void {
        > > > this.widget = value;
        > > > }
        > > >
        > > > }
        > > > }
        > > >
        > > > The lines that are highlighted are the ones marked as
errors by 
        the
        > > > compiler under Hotfix3, Flex 2.0.1.
        > > >
        > > > I thought I was following the examples shown on p. 
        135 "Overriding
        > > > getters and setters" in the Programming ActionScript 3.0
manual.
        > > >
        > > > Can anyone point out to me why this is not working?
        > > >
        > > > __._,_
        > > >
        > > 
        > >
        >
        
        

        

        


 

Reply via email to