7/29/11

Overloading in Flex



 Dear folks ,
One important question thats been asked by most of the interviewer  is overloading in flex. Flex Does not support Overloading . If we want to make use of those functionality then some work around has to be done . Following example will illustrate the reason


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;

            private function overloadtest():void
            {
                Alert.show("No argument method overload");
            }

// the following method is a overloaded method , at compile time this method will show error "Duplicate function overloading."
            private function overloadtest(e:String):void
            {
                Alert.show("single  argument method overload --- " + e);
            }
        ]]>
    </mx:Script>
    <mx:Button x="111" y="188" label="type1" click="overloadtest();"/>
    <mx:Button x="333" y="188" label="type2" click="overloadtest('type2');"/>

</mx:Application>




This behavior maybe is because Action Script follows the ECMA Script standard. A function is indeed one property of the object, so, like you CAN'T have two properties with the same name, you CAN'T have two functions with the same name. (This is just a hypothesis)


 when you declare a function like
function Identifier(arg0, arg1) {
    // body
} 



It created a variable object with name Identifier and value equals to function object  like the this new Function(arg0,arg1,body) . So we cannot have the more than one property for the current variable object with the same name .


Courtesy : 
Internet




No comments:

Post a Comment

Popular Posts