tags:

views:

251

answers:

2
override public function set data(value:object):void {

super.data = value 

}

Is this function only called when i have a itemRenderer or i can override this method in any other page or component to get the data of previous ones.

A: 

This is called any time someone tries to call x.data = foo; You can call it manually, but some components like ItemRenderer have an interface definition that requires to to exist. (IDataRenderer).

Glenn
+1  A: 

In more basic terms, you can override any public or protected function that exists in the extended class(es). This includes Setters and Getters of public properties.

The code above is essentially useless. You basically want to use setters and getters when you want something else to occur base on the setting of a property - for instance, when you set the data property of an itemRenderer, you want to inspect the data, and if it meets a certain criteria, you want to change the styling of the renderer.

Here's an example of how overriding works - what will work/what wont' work:

package
{
    public class SomeClass
    {
        public var someProp:Object; // can be overridden using setter and/or getter in sub-class

        private var otherProp:Object;  // cannot be accessed or overridden by sub-class

        public function doSomething():void // can be overridden in sub-class
        {
            // ...
        }

        protected function doSomethingElse():void // can be overridden using in sub-class
        {
            // ...
        }

        private function doSomethingPrivate():void // cannot be accessed/called nor overridden in sub-class
        {
            // ...
        }
    }
}


package
{
    public class SomeClassSub extends SomeClass
    {
        public var someProp:Object; // throws exception

        private var otherProp:Object;  // this will work

        public function doSomething():void // throws exception
        {
            // ...
        }

        override public function doSomething():void // this will work
        {
            // ...
        }

        protected function doSomethingElse():void // throws exception
        {
            // ...
        }

        override protected function doSomethingElse():void // this will work
        {
            // ...
        }

        private function doSomethingPrivate():void // this will work
        {
            // ...
        }

        override private function doSomethingPrivate():void // throws exception
        {
            // ...
        }
    }
}
Eric Belair