4 Replies Latest reply on Nov 7, 2012 3:00 PM by usoldier18

    Can I have a slider value dictate what constant is displayed in a label?

    usoldier18

      Here is my sample code so far:

       

      <?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" minWidth="955" minHeight="600">

       

        <fx:Declarations>

       

        <!-- Place non-visual elements (e.g., services, value objects) here -->

       

       

        </fx:Declarations>

       

       

       

        <fx:Script>

       

                          <![CDATA[

                                    const CONVERSION100:Array = ["150","333","543","9342"];

                                    const CONVERSION250:Array = ["202","378","590","9672"];

                                    const CONVERSION300:Array =["230","403","600","9878"];

                                    const CONVERSIONUSER:Array = ["100","250","300"];

                                    import mx.events.SliderEvent;

       

                                    protected function valueSliderChangeHandler(event:Event):void

       

                                    {

       

       

       

                                              valueLabel.text = CONVERSION100[event.currentTarget.value];

       

                                    }

       

                          ]]>

       

        </fx:Script>

       

                <s:Panel x="199" y="141" width="250" height="200">

       

                          <s:HSlider id="valueSlider" x="10" y="41" liveDragging="true" maximum="3" minimum="0"

                                                 showDataTip="false" stepSize="1" value="1"/>

                          <s:HSlider id="valueSlider2" x="138" y="41" liveDragging="true" maximum="3" minimum="0"

                                                 showDataTip="false" stepSize="1" value="1"/>

                          <s:HSlider id="userPickedSlider" x="74" y="85" liveDragging="true" maximum="2" minimum="0"

                                                 showDataTip="false" stepSize="1" value="1"/>

                          <s:Label id="valueLabel" x="45" y="22" text= "{CONVERSION100[valueSlider.value]}"/>

                          <s:Label id="valueLabel2" x="176" y="21" text= "{CONVERSION250[valueSlider2.value]}"/>

                          <s:Label id="variableLabel" x="115" y="65" text= "{CONVERSIONUSER[userPickedSlider.value]}"/>

        <s:Label id="userPickedLabel" x="104" y="126" text="What to place here?"/>

       

       

        </s:Panel>

      </s:Application>

       

       

      On the lable "userPickedLabel" text what can I place there to have userPickedSlider dictate what is displayed? I have tried, just guessing and failing,

      text= {CONVERSION{CONVERSIONUSER[userPickedSlider.value]}[valueSlider.value]}

      text= {CONVERSION(userPickedSlider.value)[valueslider.value]}

      text= {CONVERSION(variableLabel.text)[valueslider.value]}

       

      my intention is to have the userpickedSlider pick which array my label draws the values from.

      Im very new to this, sorry if not clear enough what Im trying to do.

      Any help will be greatly appreciated

        • 1. Re: Can I have a slider value dictate what constant is displayed in a label?
          pauland Level 4

          It's not clear what you are trying to do. You really need to think about what you are writing and stop guessing what might work.

           

          It looks like you have already written the answer you need:

           

          <s:Label id="variableLabel" x="115" y="65" text= "{CONVERSIONUSER[userPickedSlider.value]}"/>

           

          so the answer may be:

           

          <s:Label id="userPickedLabelx="104" y="126" text= "{CONVERSIONUSER[userPickedSlider.value]}"/>

          • 2. Re: Can I have a slider value dictate what constant is displayed in a label?
            usoldier18 Level 1

            I have three arrays that I want to draw values from for calculations

            CONVERSION100

            CONVERSION250

            CONVERSION350

            I understand how to display the cutom slider values as text now

            But now Im trying to have a sliders value dictate the array "100" "250" or "350" in the "{CONVERSIONxxx[userPickedSlider.value]}"

            the value of userPickSlider is what I need in place of xxx

             

             

             

            Yes guessing is the wrong word to use here, I tried to apply previous lessons to get what Im looking for and have failed so far.

             

            I need "{CONVERSIONxxx[valueSlider.value]}" where xxx is "{CONVERSIONUSER[userPickedSlider.value}"

            • 3. Re: Can I have a slider value dictate what constant is displayed in a label?
              pauland Level 4

              <?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" minWidth="955" minHeight="600">

                 

                 

                 

                  <fx:Declarations>

                     

                     

                     

                      <!-- Place non-visual elements (e.g., services, value objects) here -->

                     

                     

                     

                     

                     

                  </fx:Declarations>

                 

                 

                 

                 

                 

                 

                 

                  <fx:Script>

               

               

               

                      <![CDATA[

                         

                          const CONVERSION100:Array = ["150","333","543","9342"];

                         

                          const CONVERSION250:Array = ["202","378","590","9672"];

                         

                          const CONVERSION300:Array =["230","403","600","9878"];

                         

                          const CONVERSIONUSER:Array = ["100","250","300"];

                         

                          const CONVERSIONPICKERS:Array = [CONVERSION100,CONVERSION250,CONVERSION300];

                         

                          import mx.events.SliderEvent;

                         

                         

                         

                          protected function valueSliderChangeHandler(event:Event):void

                             

                             

                             

                          {

                             

                             

                             

                             

                             

                             

                             

                              valueLabel.text = CONVERSION100[event.currentTarget.value];

                             

                             

                             

                          }

                         

                         

                         

                      ]]>

                     

                     

                     

                  </fx:Script>

                 

                 

                 

                  <s:Panel x="199" y="141" width="250" height="200">

                     

                     

                     

                      <s:HSlider id="valueSlider" x="10" y="41" liveDragging="true" maximum="3" minimum="0"

                                

                                 showDataTip="false" stepSize="1" value="1"/>

                     

                      <s:HSlider id="valueSlider2" x="138" y="41" liveDragging="true" maximum="3" minimum="0"

                                

                                 showDataTip="false" stepSize="1" value="1"/>

                     

                      <s:HSlider id="userPickedSlider" x="74" y="85" liveDragging="true" maximum="2" minimum="0"

                                

                                 showDataTip="false" stepSize="1" value="1"/>

                     

                      <s:Label id="valueLabel" x="45" y="22" text= "{CONVERSION100[valueSlider.value]}"/>

                     

                      <s:Label id="valueLabel2" x="176" y="21" text= "{CONVERSION250[valueSlider2.value]}"/>

                     

                      <s:Label id="variableLabel" x="115" y="65" text= "{CONVERSIONUSER[userPickedSlider.value]}"/>

                     

                      <s:Label id="userPickedLabel" x="104" y="126" text="{CONVERSIONPICKERS[userPickedSlider.value][valueSlider.value]}"/>

                     

                     

                     

                     

                     

                  </s:Panel>

                 

              </s:Application>

              • 4. Re: Can I have a slider value dictate what constant is displayed in a label?
                usoldier18 Level 1

                Awesome, thank you very much yet again