4 Replies Latest reply on Oct 17, 2009 2:38 PM by Evgeniy_M

    [not solved] The "change" event of a slider is fired on creation. How to modify this?

    vpxav

      Hello,

      I placed a HSlider inside a repeater.

      Here's my HSlider:

      <mx:HSlider id="desiredHumiditySlider"
           width="100%"
           minimum="0"
           maximum="100"
           dataTipPlacement="bottom"
           labels="['0%','50%','100%']"
           snapInterval="1"
           tickInterval="25"
           liveDragging="false"
           allowTrackClick="true"
           value="{infosRepeater.currentItem.@act_value}"
           change="sliderChanged(event);"
      />
      

       

      My problem is that the sliderChanged function is called not only when I moved the slider's cursor, but also when the page is created.

      How to change this?

      Thanks a lot

        • 1. Re: [not solved] The "change" event of a slider is fired on creation. How to modify this?
          Evgeniy_M

          Hello,

           

          In my test, the slider does not send the change event on creation. Here is my code.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application
               xmlns:mx="http://www.adobe.com/2006/mxml"
               layout="absolute"
          >
          <mx:HSlider id="desiredHumiditySlider"
               width="100%"
               minimum="0"
               maximum="100"
               change="sliderChanged(event);"
          />
          <mx:Script>
               <![CDATA[
                    import mx.events.SliderEvent;
                    private function sliderChanged(_ : SliderEvent) : void {
                         trace("Slider changed");
                    }
               ]]>
          </mx:Script>
          </mx:Application>
          

           

          This does not print anything until I actually drag the slider.

           

          Evgeny

          • 2. Re: [not solved] The "change" event of a slider is fired on creation. How to modify this?
            vpxav Level 1

            Hello.

            First of all, thanks for trying to help and sorry for the late reply...

             

            If I doing like you, there is no problem but the thing is that you're not using a repeater.

            In my page, the slider is in a repeater and then I have my problem

             

            Thanks...

            • 3. Re: [not solved] The "change" event of a slider is fired on creation. How to modify this?
              Evgeniy_M Level 1

              Well, I tried putting the slider in the repeater (see the attachment), and again no change event is sent before I change them manually.

               

              Regardless, you can add the event listeners after the program creation is complete. Make a listener on creationComplete event and add the listener to the sliders in Actionscript.

               

              Evgeny

              • 4. Re: [not solved] The "change" event of a slider is fired on creation. How to modify this?
                Evgeniy_M Level 1

                Well, I tried putting the sliders in a repeater, and again no change event is sent until I change them manually.

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application
                     xmlns:mx="http://www.adobe.com/2006/mxml"
                     layout="vertical"
                     backgroundColor="white"
                >
                <mx:Array id="dp">
                     [10, 50, 20, 60]
                </mx:Array>
                <mx:Repeater id="infosRepeater" dataProvider="{dp}">
                <mx:HSlider
                     minimum="0"
                     maximum="100"
                     value="{infosRepeater.currentItem}"
                     change="sliderChanged(event);"
                />
                </mx:Repeater>
                
                <mx:Script>
                     <![CDATA[
                          import mx.events.SliderEvent;
                          private function sliderChanged(_ : SliderEvent) : void {
                               trace("Slider changed");
                          }
                     ]]>
                </mx:Script>
                </mx:Application>
                
                

                 

                Regardless, you can add the listeners after the program initialization. Create a listener for creationComplete or some other late event and in it add the listener to each slider using Actionscript. For example,

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application
                     xmlns:mx="http://www.adobe.com/2006/mxml"
                     layout="vertical"
                     backgroundColor="white"
                >
                
                <mx:Array id="dp"> [1, 5, 2, 6] </mx:Array>
                
                <mx:Repeater id="infosRepeater" dataProvider="{dp}">
                <mx:HSlider value="{infosRepeater.currentItem}"/>
                </mx:Repeater>
                
                <mx:Button click="initSliders()"/>
                
                <mx:Script>
                     <![CDATA[
                          import mx.events.SliderEvent;
                          private function initSliders() : void {
                               for (var i : int = 0; i < numChildren; i++)
                                    if (getChildAt(i) is HSlider)
                                         getChildAt(i).addEventListener(SliderEvent.CHANGE, sliderChanged);
                          }
                          
                          private function sliderChanged(_ : SliderEvent) : void {
                               trace("Slider changed");
                          }
                     ]]>
                </mx:Script>
                </mx:Application>
                
                

                 

                Evgeny