--- In [email protected], "johantrax" <[EMAIL PROTECTED]>
wrote:
>
> Hi all,
> 
> Currently I'm working with a custom DateField, being a canvas with 2
> states: "text" and "insert", and a public bindable property value:Date
> 
> the component:
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";
>      currentState="text"
>      creationComplete="init()"
> >
> 
>      <mx:Style>
>          .vet { font-weight: bold; }
>      </mx:Style>
> 
>      <mx:Script>
>          <![CDATA[
>              import mx.binding.utils.BindingUtils;
>              //possible states
>              public static var STATE_VIEW:String = "text";
>              public static var STATE_INSERT:String = "insert";
> 
>              [Bindable]
>              public var value:Date = new Date();
> 
>              private function init():void
>              {
>                  BindingUtils.bindSetter(function(arg:*):void{ value =
> Date(arg as String); }, this, ["df", "text"]);
>              }
> 
>          ]]>
>      </mx:Script>
> 
> <mx:states>
>      <!-- display the plain text //-->
>      <mx:State name="text">
>          <mx:AddChild>
>              <mx:target>
>                  <mx:HBox>
>                      <mx:Text text="{this.label}" styleName="vet" />
>                      <mx:Text text="{this.value}" />
>                  </mx:HBox>
>              </mx:target>
>          </mx:AddChild>
>      </mx:State>
>      <!-- display the DateField as formitem //-->
>      <mx:State name="insert">
>          <mx:AddChild>
>              <mx:target>
>                  <mx:FormItem label="{this.label}">
>                      <mx:DateField id="df" text="{this.value}"
> editable="true" formatString="DD/MM/YYYY" firstDayOfWeek="1" />
>                  </mx:FormItem>
>              </mx:target>
>          </mx:AddChild>
>      </mx:State>
> </mx:states>
> 
> </mx:Canvas>
> 
> Now in my app (simplified for this example)  I have 2 instances of this
> component, one in inputState (id = in) and one in textState (id = view).
> Next to them is a button which click-function is as follows:
> public function setFilterText():void
> {
>          if (in.value as String == "")
>              in.value = "(none)";
>          view.value = in.value;
>          //empty input
>          in.value = null;
>      }
> }
> 
> Somehow this doesn't work, at all. Neither the value is passed on, nor
> the inputDateField is set blank again.
> Any thoughts?
> 
> --jeetee
>
posted too soon:
Above gives following warning:
Date(x) behaves the same as new Date().toString(). To cast a value to
type Date use "x as Date" instead of Date(x).

However I do get the dateString of todays date upon loading (after
spamming errors about the failed conversion)

But when changing the bindsetter to us (arg as Date), as suggested by
the warning, both errors and result are gone :(

--Johan

Reply via email to