Quantcast
Viewing all articles
Browse latest Browse all 10

Flex DateChooser – Background color for SMTWTFS header – solution 2

Here is the second approach to solving the problem I descibed in this post:

http://blog.flexmonkeypatches.com/2008/09/02/flex-datechooser-background-color-for-smtwtfs-header-solution-1/

Download a zipfile containing the source to this sample.

Browse the source of this example.

Or continue into the blog entry to see the source:

Here is the app code:

  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         xmlns="*" viewSourceURL="srcview/index.html">
  5.  
  6.         <myDC id="myDC"/>
  7.  
  8. </mx:Application>
  9.  

Here is the code for the custom component:

  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <mx:DateChooser xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         creationComplete="onCreationComplete()">
  5.         <mx:Script>
  6.                 <![CDATA[
  7.                         import mx.core.UITextField;
  8.                         use namespace mx_internal;
  9.  
  10.                         private function onCreationComplete():void{
  11.                         //super.createChildren();
  12.                                 // note need to do this later in creation cycle to get measured properties
  13.                                 // so do this in creationComplete rather than createChildren
  14.                                 var first:UITextField = mx_internal::dateGrid.dayBlocksArray[0][0] as UITextField;
  15.  
  16.                                 // note fudge factors below to account for padding
  17.                                 // actual values may be able to get from various padding styles using getStyle
  18.  
  19.                                 var ht:int=first.measuredHeight + 6;
  20.                                 var wdth:int=this.measuredWidth4;
  21.                                 var ypos:int=mx_internal::dateGrid.y + 2;
  22.  
  23.                                 var bar:Sprite = new Sprite();
  24.                                 bar.graphics.beginFill(0xDDDDDD);
  25.                                 //note starting drawing at x = 2 instead of 0
  26.                                 bar.graphics.drawRect(2,ypos,wdth,ht);
  27.                                 // set alpa of dateGrid so background shows through.
  28.                                 mx_internal::dateGrid.alpha=.5;
  29.                                 //add background at same pos as dateGrid (so that it appears at proper z-order)
  30.                                 this.addChildAt(bar,this.getChildIndex(mx_internal::dateGrid));
  31.                         }
  32.                 ]]>
  33.         </mx:Script>
  34.  
  35. </mx:DateChooser>
  36.  

Viewing all articles
Browse latest Browse all 10

Trending Articles