First of all, I would read Creating and Extending Flex 2 Components >
Creating Nonvisual Flex Components > Creating Custom Formatters >
Creating a custom formatter in the documentation.
The documentation for DateFormatter says that it has a formatString
variable, so you can get rid of str_dateFormat and just use formatString
on your tag. Also, the correct function to override in your custom
formatter is format() so you can replace getFormattedDate() with:
override public function format(value:Object):String
{
return super.format(value);
}
Then, you can add this public getter function to bind your
str_formattedDate.
public function get formattedDate():String
{
return format(str_dateString);
}
Then, change {qdf.str_formattedDate} to {qdf.formattedDate}. I believe
this should work, report back if you encounter any problems.
--- In [email protected], "ben.clinkinbeard"
<[EMAIL PROTECTED]> wrote:
>
> OK, I've made a modified version more suitable for MXML and would love
> to get feedback from everyone. Ideally I would be able to bind a field
> or label directly to the formatted output and would not require a
> click to 'reset' the field that is bound to the formatted value. How
> would I accomplish that? (I tried but was unsuccessful.) Here is the
> modified class:
>
> public class QuickDateFormatter extends DateFormatter
> {
> public var str_dateString:String;
> public var str_dateFormat:String;
> [Bindable] public var str_formattedDate:String;
>
> public function getFormattedDate():void
> {
> var f:DateFormatter = new DateFormatter();
> f.formatString = str_dateFormat;
> str_formattedDate =
> f.format(DateFormatter.parseDateString(str_dateString));
> }
> }
>
> and a sample usage:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> layout="absolute" xmlns:local="*">
> <local:QuickDateFormatter id="qdf" str_dateString="{d.text}"
> str_dateFormat="{f.text}" />
> <mx:Label text="{qdf.str_formattedDate}" x="72" y="168"/>
> <mx:TextInput x="72" y="117" width="133" id="d"/>
> <mx:TextInput x="222" y="117" width="91" id="f"/>
> <mx:Label x="72" y="91" text="Date"/>
> <mx:Label x="222" y="91" text="Format"/>
> <mx:Button x="341" y="117" label="Go"
click="qdf.getFormattedDate();"/>
> </mx:Application>
>
> Thanks,
> Ben
> http://www.returnundefined.com
>
>
>
>
> --- In [email protected], "gotgoose09" thegoosmans@ wrote:
> >
> > All you have to do is add public properties like this:
> >
> > [Bindable]
> > public var str_dateFormat:String;
> > [Bindable]
> > public var str_dateString:String;
> > --- In [email protected], "ben.clinkinbeard"
> > <ben.clinkinbeard@> wrote:
> > >
> > > Yea, what I am looking for is some help on what changes would need
to
> > > be made to the class to allow it to be used in a format similar to
> this:
> > >
> > > <utils:QuickDateFormatter id="qdf"
str_dateString="{model.someDate}"
> > > str_dateFormat="MM/DD/YY" />
> > > <mx:Label text="{qdf}" />
> > >
> > > Thanks,
> > > Ben
> > >
> >
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Something is new at Yahoo! Groups. Check out the enhanced email design.
http://us.click.yahoo.com/SISQkA/gOaOAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/