[ 
https://issues.apache.org/jira/browse/FLEX-12745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13675462#comment-13675462
 ] 

Mark Kessler commented on FLEX-12745:
-------------------------------------

Can reproduce issue with below test application.  Mouse click on tab produces 
one selectedtIndex change while the programmatic change produces the 3 
selectedIndex changes.  


<?xml version="1.0" encoding="utf-8"?>
<!---
   Test application
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="onCreationComplete();" > 

    <fx:Script>
        <![CDATA[

        import mx.binding.utils.BindingUtils; 

        protected function onCreationComplete():void
        {
            BindingUtils.bindSetter(bindingDest, theTabBar, "selectedIndex"); 
        }


        private function triggerBug():void
        {
            theTabBar.selectedIndex = 2;
            //Note: trace() will also work wrong here - it will display old 
value of selectedIndex, not the one that was just set above!
            trace("triggerBug(): selectedIndex now = "+theTabBar.selectedIndex);
        }

        private function bindingDest(newVal:*):void
        {
            trace("bindingDest(): binding executed! newVal="+newVal);
        }
        
        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout horizontalAlign="center" verticalAlign="middle" 
gap="0" />
    </s:layout>


    <mx:TabBar id="theTabBar" dataProvider="{['Tab1', 'Tab2', 'Tab3']}" 
selectedIndex="1" />
    <mx:HRule />
    <mx:Button label="Trigger bug" click="triggerBug()" />

</s:Application>
                
> TabBar: databinding executed three times when selectedIndex set 
> programatically
> -------------------------------------------------------------------------------
>
>                 Key: FLEX-12745
>                 URL: https://issues.apache.org/jira/browse/FLEX-12745
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: mx: Tab Bar
>    Affects Versions: Adobe Flex SDK 2.0.1 (Release)
>         Environment: Affected OS(s): All OS Platforms
> Language Found: English
>            Reporter: Adobe JIRA
>              Labels: easytest
>
>       Description:
> When TabBar's selectedIndex is changed programatically, any bindings to 
> selectedIndex are executed three times: once with previous selectedIndex 
> value, and twice with new value. Changing selectedIndex by clicking tabs with 
> mouse works as expected though - bindings occur once.
> This bug will therefore cause all setters, <observe> tags etc watching 
> selectedIndex property to be called 3x more than necessary, which - depending 
> on their purpose - sometimes can be tolerated, but definitelly is not 
> optimized.
> I noticed that bug when trying to find some workaround for another bug in 
> TabBar (reported as SDK-13029). It ruined quite a good workaound I was 
> testing :/
> Steps to reproduce:
> Run following code to see the bug
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical" 
> applicationComplete="initApp()" >
>       <mx:TabBar id="theTabBar" dataProvider="{['Tab1', 'Tab2', 'Tab3']}" 
> selectedIndex="1" />
>       <mx:HRule />
>       <mx:Button label="Trigger bug" click="triggerBug()" />
>       <mx:Script>
>               <![CDATA[
>                       import mx.binding.utils.BindingUtils;
>                       /**
>                        * Setup test binding
>                        * The same (triple call) behaviour would happen when 
> binding with <mx:Binding> tag.
>                        */
>                       private function initApp():void {
>                               BindingUtils.bindSetter(bindingDest, theTabBar, 
> "selectedIndex");
>                       }
>                       
>                       /**
>                        * Trigger TabBar bug: programatically change its 
> selectedIndex.
>                        * Any bindings to selectedIndex will be executed three 
> times:
>                        * - once with old selectedIndex value
>                        * - twice with new value
>                        */
>                       private function triggerBug():void {
>                               theTabBar.selectedIndex = 2;
>                               //Note: trace() will also work wrong here - it 
> will display old value of selectedIndex, not the one that was just set above!
>                               trace("triggerBug(): selectedIndex now = 
> "+theTabBar.selectedIndex);
>                       }
>                       
>                       /**
>                        * Example databinding target
>                        * Will be bound to TabBar's selectedIndex property.
>                        */
>                       private function bindingDest(newVal:*):void {
>                               trace("bindingDest(): binding executed! 
> newVal="+newVal);
>                       }
>               
>               ]]
>       >
>       </mx:Script>     
> </mx:Application>
>  
> Actual Results:
>  After selectedIndex is changed programatically, bindings to selectedIndex 
> will be executed three times: once with previous selectedIndex value, and 
> twice with new value.
>  
> Expected Results:
>  After selectedIndex is changed programatically, bindings to selectedIndex 
> will be executed once, with new value (exactly the same behaviour as if tab 
> was clicked by user with a mouse).
>  
> Workaround (if any):
>  None found.
>     

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to