5 Replies Latest reply on Apr 9, 2009 3:09 AM by vpxav

    [not solved] get a HSlider's value on change inside a REPEATER

    vpxav
      Hello everyone,
      I'm new to Flex (3) and I've coded a Repeater containing HSliders.
      When I move a slider, I would like to be able to send its new value to a php script (update_element.php) via the POST method.
      I can post the "element_id" but not the "target" that has to receive the HSlider's new value after the user changed it.
      What's the correct code? Can you explain a little bit?
      Here's my code...
      Thanks a lot!
        • 1. Re: [not solved] get a HSlider's value on change inside a REPEATER
          Peter Hahmann Level 1
          vpxav,

          I know thet there is a property of the repeater that is getRepeatedItem, but I'm not used to Repeaters anymore as I had some trouble in the past. I'd rather use a for to add multiple components to my "form", set the components data and if needed add the components to an array/arraycollection. If you intend to change your components logic, I'd be pleased to help you out.

          Regards,
          Peter
          • 2. Re: [not solved] get a HSlider's value on change inside a REPEATER
            vpxav Level 1
            Hello Peter,
            Thank you for your answer.
            Most urgent for me is to find a working solution. So, I'm not unwilling to change my components logic and would be very happy if you could help.

            But, I would also be happy to have an explanation on how to do this with a repeater as I have a lot of repeaters in my application.
            Thank you for your time.
            • 3. Re: [not solved] get a HSlider's value on change inside a REPEATER
              Peter Hahmann Level 1
              vpxav,

              I've tried to get you an answer with te repeater, but I got stuck, so i'll at least explay you how to use it without a repeater.

              Regards,
              peter

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
              <mx:Script>
              <![CDATA[
              import mx.rpc.events.ResultEvent;
              import mx.controls.VSlider;
              import mx.controls.CheckBox;
              import mx.events.ListEvent;
              import mx.collections.ArrayCollection;
              [Bindable]
              private var arrc:ArrayCollection = new ArrayCollection([{id:1, item1:'Red', item2:'Pink'},{id:2, item1:'Green', item2:'Yellow'}])

              private var arrcSld:ArrayCollection;

              /**
              * Here is where you get all records form your Database
              * and create your sliders
              * */
              private function init():void{
              var vsld:VSlider;
              //You'll loop all records that came from your database
              //Create a new Vslider for each records, set the properties
              // and add the slider to the slidercollection and to your box/display
              for each(var obj:Object in arrc){
              vsld = new VSlider();
              vsld.labels = [obj.item1,obj.item1];
              vsld.data = obj;
              vsld.addEventListener(Event.CHANGE, chk_changeHandler);
              arrcSld.addItem(vsld);
              box.addChild(vsld);
              }
              }

              /**
              * Here is where you'll call the RempoteObjet to update your Database
              * */
              private function chk_changeHandler(e:Event):void{
              //You busines logic
              //You busines logic
              }

              /**
              * Here is where you cature the result of your Database select
              * */
              private function business_resulthandler(obj:Object):void{
              //You'll loop all sliders in the ArrayCollection and once you get the slider
              //With the same ID of your Database object, you can update the values
              for each(var vsld:VSlider in arrcSld){
              if(vsld.data.id == obj.id){
              vsld.value = obj.value;
              }
              }
              }

              ]]>
              </mx:Script>
              <mx:VBox id="box" top="0" left="0" right="0" bottom="0"/>
              </mx:Application>
              • 4. Re: [not solved] get a HSlider's value on change inside a REPEATER
                Level 7

                "vpxav" <webforumsuser@macromedia.com> wrote in message
                news:gqta8a$qas$1@forums.macromedia.com...
                > Hello everyone,
                > I'm new to Flex (3) and I've coded a Repeater containing HSliders.
                > When I move a slider, I would like to be able to send its new value to
                > a
                > php script
                (update_element.php) via the POST method.
                > I can post the "element_id" but not the "target" that has to receive the
                > HSlider's new value after the user changed it.
                > What's the correct code? Can you explain a little bit?
                > Here's my code...
                > Thanks a lot!

                You can add event listeners to all of the sliders by looping through all the
                references
                ( http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf q9). In
                the event handler, you can figure out which slider fired the event and route
                the value appropriately.

                HTH;

                Amy


                • 5. Re: [solved] get a HSlider's value on change inside a REPEATER
                  vpxav Level 1

                  Hello,

                  thank your for having answered to my questions, I did not see it before as the forums where down a few days and did not come after that before today.

                  I found a working solution by myself.

                  Here it is:

                   

                  I used the change property of the sliders:

                  [quote]

                  change="sliderChanged(event)"

                  [/quote]

                   

                  The function is the following:

                  [quote]

                   

                  private function sliderChanged(event:SliderEvent):void

                  {

                   

                   

                  var currentSlider:Slider=Slider(event.currentTarget);

                  formTarget.text=String(currentSlider.value);

                  }

                  [/quote]

                   

                  so formTarget.text is a text component that receives the new value of ANY slider that changes.

                   

                  Of course I can't tell which slider changed... but this is another question so I will open another topic for it.

                   

                  Thank you for your help.