2 Replies Latest reply: Apr 18, 2013 9:27 AM by profesorAntonio RSS

    Change Event dispatched 2 times in List Component

    sebastiantoro84

      Hi,

          Thanks for taking the time to read about my problem. I have a List component which has a simlpe array of strings as a dataprovider. I'm using the change event to call a method and I don't know why this method gets called 2 times.

       

      ¿Someone knows why this keeps happening?

       

      Thanks for your help.

       

      Sebastián Toro

        • 1. Re: Change Event dispatched 2 times in List Component
          hd465 Community Member

          Impossible to guess (show Your code ). I created a s:List component, set dataProvider and it works correctly (only one Alert appears when I select an item):

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <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"">
          
               <fx:Script>
                    <![CDATA[
                         import mx.collections.ArrayCollection;
                         import mx.controls.Alert;
          
                         [Bindable]
                         private var listFeed:ArrayCollection = new ArrayCollection(['A', 'B', 'C']);
          
                         protected function changeHandler(event:IndexChangeEvent):void {
                              Alert.show('yah');
                         }
                    ]]>
               </fx:Script>
          
               <s:List id="lista" dataProvider="{listFeed}"
                         change="changeHandler(event)"/>
          
          </s:Application>
          
          • 2. Re: Change Event dispatched 2 times in List Component
            profesorAntonio

            If an s:List, you put a IndexChangeEvent listener the event, and in that event, cast a filterFunction to the dataProvider of that List ...
            You will have to validate inside that function through property IndexChangeEvent newIndex of greater than or equal to ZERO.
            Because interestingly, the dataProvider of the List filter is invoked IndexChangeEvent again, but now the newIndex, give a value of "-1", leading with it the entire event, from null and associated with this throw this:
            Error # 1009: Can not access a property or method of a null object reference.
            When referring to the event ... :/