why and when override public function set data

450 views Asked by At

I had make some research over the internet about the itemRender i just found some articles that describe the itemRender like Adobe Item Render , The Best Practice with item render in flex development all these articles explain how ItemRender works? But they did not specified why we are overriding the set data method? Why we are calling super.data = value? Hope you will help me.

 <s:itemRenderer>
 <fx:Component>                 
 <s:ItemRenderer autoDrawBackground="false" width="100%" height="100%" >                        
 <fx:Script>                     
    override public function set data(value:Object):void
    {
        super.data = value; }

                        ]]>

               </fx:Script>                     
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>                    
1

There are 1 answers

0
Brian On BEST ANSWER

Note that overriding the set data method isn't always necessary. You can use the binding syntax and rely on the default ItemRenderer's set data function, e.g.

<s:Label text="{data.labelText}" />

That being said, overriding set data allows you to trigger more complex behaviors when a new element is being displayed. One possible use for this is a scrolling list where each entry glows for about half a second when it first comes into view.

Calling super.data = value; in your override function simply invokes the default behavior, in this case setting ItemRenderer's underlying data property It's standard practice to do this in an override unless you're actively trying to avoid doing something that the parent class does.