1

I got a Problem with my DateChooser. When clicking the control directly it highlights the date as it should. When selecting the date programmatically it won't show.

var date:Date = notification.getBody() as Date;
_view.dcMiniCalendar.selectedDate = date;

trace tells me, that date and _view.dcMiniCalendar.selectedDate carry the correct values.

I already tried to use _view.dcMiniCalendar.invalidateDisplayList() (and some other invalidate functions as well) but neither with nor without them I get that date to be shown selected in the control.

thx in advance. x_mtd

Max
  • 180
  • 4
  • 13
  • Don't use 'as' because it just returns null when it can't cast it. Use a hard cast like `Date(notification.getBody())` but make sure that body is an actual date or else you'll get a runtime error. You might need to convert it yourself. – J_A_X May 26 '11 at 13:12
  • @J_A_X: this doesn't seem to be the problem. I now statically assign that value with `_view.dcMiniCalendar.selectedDate = new Date(2011, 4, 15);` but w/o effect. hmm... I start wondering if this effect could be caused by the style I am using for selection. But then it shouldn't work either way, right? – Max May 26 '11 at 13:41
  • Show more code. You might be setting it before the calendar is ready. – J_A_X May 26 '11 at 13:44

1 Answers1

2

Are you sure that notification.getBody() returns a valid date?

Mine works just fine.

<mx:DateChooser id="dateChooser" />

<s:Button click="button1_clickHandler(event)" />

protected function button1_clickHandler(event:MouseEvent):void
{
    var myDate:Date = new Date(2012, 11, 21);
    dateChooser.selectedDate = myDate;
}

What is the return type of notification.getBody() ? If it is a string, parse it using Date.parse()

Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
  • thx for your answer, but as posted in comment above this doesn't work for me. – Max May 26 '11 at 13:42
  • So are you sure that `date` becomes a proper `Date` object ? Did you try checking out after its created whether all the fields are properly filled? Try running my example and see if it works. Also what does notification.getBody() return? What type ? – Ranhiru Jude Cooray May 26 '11 at 13:46
  • Thx for your help. Finally the problem was on another place: Using PureMVC I did not mind, that my mediator is used on another view. Due to that my function already worked, but I only didn't see ... kind of stupid :S – Max May 31 '11 at 16:09