PDA

View Full Version : Flex 3: How to resolve error with DateField being Null value


jarmanje
09-26-2008, 12:50 AM
Hello,

I have been playing with Flex on and off for a while now. I'm getting the hand of it more, but it's simple problems I can't resolve!

I have a DateField which is loaded from a mysql Database, it all works fine. My problem is when creating a new record in my database (so my array is set to nothing at this point..) and when the value in the database is NULL

here is my datagrid:
<mx:DateField id = "orderdate" formatString="YYYY-MM-DD" width="170" showToday="true" text ="{currentOrder.date}"/>

and here is my error on line 446 of DateField.as:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.controls::DateField$/stringToDate()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ controls\DateField.as:446]
at mx.controls::DateField/displayDropdown()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ controls\DateField.as:2118]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:8565]
at mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:8508]

Perhaps I add a check if the array value is null and if so make it todays date? How can i do this?



Also, just very quickly. How can i change the .x positon of an addchild. It is top left at the moment...
<mx:AddChild relativeTo="{this}"
position="lastchild"
creationPolicy="all">
<forms:OrderForm id="OrderForm"
cancel="currentState=null"
save="saveRecord(event)"/>
</mx:AddChild>

rawmantick
09-26-2008, 07:34 AM
<mx:DateField id = "orderdate" formatString="YYYY-MM-DD" width="170" showToday="true" text ="getDate()"/>

and

private function getDate():String
{
if( currentOrder==null )
return (new Date()).toString;
return currentOrder.date;
}

Hope it's what you need...

jarmanje
09-26-2008, 11:20 AM
Thank you so much. this looks about perfect for what i want

jarmanje
10-01-2008, 12:04 PM
Hi there,

it just says in the dataField text "getDate()"

i dont think it is calling the function correctly, its just putting the text as the function name