![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
I have a slider like so:
<mx:HSlider id="myslider" width="245" allowThumbOverlap="true" thumbCount="1" snapInterval="1" tickInterval="1" values="[11]" labels="['Jan', 'Dec']" minimum="1" maximum="12" change="sliderChangeTwo(event)" dataTipFormatFunction="getSliderLabel" themeColor="#73B9B9"/> every month I go in and change the values to the current month like November is 11. How can I have it shoe this month automatically. I have been looking at the date stuff but there is an error because dates are strings and the slider acceps numbers. Any thoughts? Thanks George |
| Sponsored Links |
|
|||
|
This works:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.events.SliderEvent; private var months:ArrayCollection = new ArrayCollection([ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private function getSliderLabel(num:Number):String{ return months.getItemAt(num-1) as String; } private function getCurrentMonth():Array{ return [new Date().getMonth()+1]; } ]]> </mx:Script> <mx:HSlider id="myslider" width="245" tickInterval="1" values="{getCurrentMonth()}" labels="['Jan', 'Dec']" minimum="1" maximum="12" dataTipFormatFunction="getSliderLabel" snapInterval="1"/> </mx:Application> |
|
|||
|
...and here's another way to do it...
View source at: http://www.anaheimwib.com/_comps/slider/ Main difference is I'm using arithmetic on the current date to get you a date one month out, and using the formatted result as a bindable in the slider labels property. Since the "futureDate" var contains today's date + one month, you could also use this var anywhere else in your code where you need the entire future date. This is useful at the end of the current year, where you might want to add two months to today's date, and get a date in 2009, for instance. I included the use of the Date formatter class to get you started on returning just a portion of a date, formatted as you wish (M="1", MM="01", MMM= "Jan", MMMM= "January"). Simply change the formatter's format string and the slider's labels will also be updated. On more thing...if you are planning on using the slider's retun value to get a month's number, remember that in actionscript the month numbering starts at 0 (you are specifying 1-12; AS uses 0-11). Complete code: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()" viewSourceURL="srcview/index.html"> <mx:Script> <![CDATA[ private var dateNow ate = new Date();private var futureDate ate = newDate(dateNow.getFullYear(),dateNow.getMonth()+2,da teNow.getDate()); private var minHSliderLabel:String; private var maxHSliderLabel:String; [Bindable] private var sliderArray:Array; [Bindable] private var currentMonth:Number = dateNow.month+1; private function initApp():void{ minHSliderLabel=myDateFormatter.format(dateNow); maxHSliderLabel=myDateFormatter.format(futureDate) ; sliderArray = [minHSliderLabel,maxHSliderLabel]; } ]]> </mx:Script> <mx ateFormatter id="myDateFormatter" formatString="MMM"/><mx:HSlider id="myslider" width="245" snapInterval="1" tickInterval="1" labels="{sliderArray}" minimum="1" maximum="12" themeColor="#73B9B9" y="26"/> </mx:Application> |
|
|||
|
Greg,
Thanks alot. I have it working to select the current month. I cannot seem to get it to start out that way. when the app loads it brings in the data, All months are shown in my chart, and the correct month (Dec) is where the thumbs is (so thats good) when I move the thumb to November it changes the chart perfect. But when it loads there are all 12 months how can I get it to just have December to start? When I move the thumb back to December it looks perfect. Thanks for all your help. George |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise