{"id":12,"date":"2009-02-22T03:39:36","date_gmt":"2009-02-22T07:39:36","guid":{"rendered":"http:\/\/blog.halnesbitt.com\/2009\/02\/22\/disabling-dates-in-flash-datepicker-component\/"},"modified":"2016-09-01T00:07:37","modified_gmt":"2016-09-01T04:07:37","slug":"disabling-dates-in-flash-datepicker-component","status":"publish","type":"post","link":"https:\/\/halnesbitt.com\/blog\/2009\/02\/22\/disabling-dates-in-flash-datepicker-component\/","title":{"rendered":"Disabling Dates in Flash DatePicker Component"},"content":{"rendered":"<p><!--more-->So I was working on a project for a client and she needed a calendar for booking appointments. However, she wanted the ability to disable dates to prevent double booking. Since the site was in Flash, I thought I would use the DatePicker component, but I was having a hard time figuring out how to do it dynamically so that she could update it. With the help of nunomira on flashkit.com, I was able to implement it very easily. The site used an access database, so I wrote a quick asp page that outputs the dates in XML and then Flash loads the variables into an  array and disables the dates. I thought I would share, in case anyone else can use this.<\/p>\n<p>Here is the actionscript. Just load this into the frame and name your datepicker &#8220;calendar&#8221;:<\/p>\n<pre>\r\n<code>\r\nvar dates_xml:XML = new XML();\r\ndates_xml.ignoreWhite = true;\r\ndates_xml.onLoad = function(ok:Boolean):Void\r\n{\r\n    if (ok)\r\n    {\r\n        var temp_xml:Array = this.firstChild.childNodes;\r\n        var n:Number = temp_xml.length;\r\n\r\n        var dates:Array = new Array();\/\/ local variable now\r\n\r\n        for (var i = 0; i < n; i++)\r\n        {\r\n            var year:Number = parseInt(temp_xml[i].attributes.year, 10);\r\n            var month:Number = parseInt(temp_xml[i].attributes.month, 10);\r\n            var day:Number = parseInt(temp_xml[i].attributes.day, 10);\r\n\r\n            dates.push(new Date(year, month, day));\r\n        }\r\n\r\n        disableDates(dates);\/\/ call the function\r\n    }\r\n};\r\ndates_xml.load(\"dates.xml\");\r\n\r\nfunction disableDates(dates:Array)\r\n{\r\n    var datesRanges:Array = new Array();\r\n\r\n    var n = dates.length;\r\n    for (var i = 0; i < n; i++)\r\n    {\r\n        var j = i % 2;\r\n        \/\/if it's odd\r\n        if (j == 0)\r\n        {\r\n            datesRanges.push({rangeStart:dates[i], rangeEnd:dates[i + 1]});\r\n        }\r\n    }\r\n\r\n    calendar.disabledRanges = datesRanges;\r\n} \r\n<\/code>\r\n<\/pre>\n<p>Here is the asp code. Note that the input month names was the actual name, so I converted them into numbers for Flash to read:<\/p>\n<pre>\r\n<code>\r\n&lt;%\r\n   ' -- show.asp --\r\n   ' Generates a list of uploaded files\r\n   \r\n   Response.Buffer = True\r\n   \r\n   ' Connection String\r\n   Dim connStr\r\n      connStr = \"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\" & _\r\n         Server.MapPath(\"dates.mdb\")\r\n\r\n   ' Recordset Object\r\n   Dim rs\r\n      Set rs = Server.CreateObject(\"ADODB.Recordset\")\r\n      \r\n      ' opening connection\r\n      rs.Open \"select * from dates \" & _\r\n\t\t\"order by [ID] desc\", connStr, 3, 4\r\n\r\nresponse.ContentType=\"text\/xml\"\r\nresponse.Write(\"&lt;?xml version='1.0' encoding='ISO-8859-1'?&gt;\")\r\nresponse.Write(\"&lt;dates&gt;\")\r\nWhile Not rs.EOF\r\n'Setting up the start year\r\n\r\nresponse.Write(\"&lt;date year=\"\"\" & rs(\"start_year\") & \"\"\"\")\r\n'converting month names to numbers for Flash to read\r\nIf rs(\"start_month\") = \"Jan\" Then \r\nresponse.Write(\" month=\"\"0\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Feb\" Then \r\nresponse.Write(\" month=\"\"1\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Mar\" Then \r\nresponse.Write(\" month=\"\"2\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Apr\" Then \r\nresponse.Write(\" month=\"\"3\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"May\" Then \r\nresponse.Write(\" month=\"\"4\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Jun\" Then \r\nresponse.Write(\" month=\"\"5\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Jul\" Then \r\nresponse.Write(\" month=\"\"6\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Aug\" Then \r\nresponse.Write(\" month=\"\"7\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Sept\" Then \r\nresponse.Write(\" month=\"\"8\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Oct\" Then \r\nresponse.Write(\" month=\"\"9\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Nov\" Then \r\nresponse.Write(\" month=\"\"10\"\"\")\r\n\r\nElseIf rs(\"start_month\") = \"Dec\" Then \r\nresponse.Write(\" month=\"\"11\"\"\")\r\n\r\nEnd If\r\n\r\nresponse.Write(\" day=\"\"\" & rs(\"start_day\") & \"\"\" \/&gt;\")\r\n\r\n\r\n'setting up the end year\r\n\r\nresponse.Write(\"&lt;date year=\"\"\" & rs(\"end_year\") & \"\"\"\")\r\n'converting month names to numbers for Flash to read\r\nIf rs(\"end_month\") = \"Jan\" Then \r\nresponse.Write(\" month=\"\"0\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Feb\" Then \r\nresponse.Write(\" month=\"\"1\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Mar\" Then \r\nresponse.Write(\" month=\"\"2\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Apr\" Then \r\nresponse.Write(\" month=\"\"3\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"May\" Then \r\nresponse.Write(\" month=\"\"4\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Jun\" Then \r\nresponse.Write(\" month=\"\"5\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Jul\" Then \r\nresponse.Write(\" month=\"\"6\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Aug\" Then \r\nresponse.Write(\" month=\"\"7\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Sept\" Then \r\nresponse.Write(\" month=\"\"8\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Oct\" Then \r\nresponse.Write(\" month=\"\"9\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Nov\" Then \r\nresponse.Write(\" month=\"\"10\"\"\")\r\n\r\nElseIf rs(\"end_month\") = \"Dec\" Then \r\nresponse.Write(\" month=\"\"11\"\"\")\r\n\r\nEnd If\r\n\r\nresponse.Write(\" day=\"\"\" & rs(\"end_day\") & \"\"\" \/&gt;\")\r\n\r\n         rs.MoveNext\r\n         Wend\r\n\r\n      \r\n      rs.Close\r\n      Set rs = Nothing\r\nresponse.Write(\"&lt;\/dates&gt;\")\r\n%&gt;\r\n\r\n<\/code>\r\n<\/pre>\n<p>You can also <a href=\"http:\/\/halnesbitt.com\/blog\/wp-content\/uploads\/2009\/02\/dates.zip\">download the fla and a static XML file<\/a> if you want to see how it's done.<\/p>\n<p>Cheers, <\/p>\n<p>Hal<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-computer-stuff","category-show-all"],"_links":{"self":[{"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":1,"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":336,"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions\/336"}],"wp:attachment":[{"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/halnesbitt.com\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}