• Last Modified
  • 17.10.2008

Flex Developer Notes

TypeError: Error #1010: A term is undefined and has no properties. (with HTTPService)

TypeError: Error #1009: Cannot access a property or method of a null object reference (with TileList/DataGrid)

In Flex, when sending a HTTP request to the server it may return no results, so if you then try to access any property of an empty response object, flex will throw an error.

In this case you might try applying a little helper function to the result object, it ensures you always have an object in return.

Below is an example. Hope this helps someone.


	
	////////////////////////////////////////////////////
	// Function that handles response from the server
	///////////////////////////////////////////////////
	public function ServerResponseHandler(evt:ResultEvent):void{
		var my_images:ArrayCollection = Response2ArrayCollection(evt.result);
	}
	
	////////////////////////////////////////////////////
	// Helper function
	////////////////////////////////////////////////////
	public function Response2ArrayCollection(obj:Object):ArrayCollection {
		var arr:ArrayCollection;
		if(obj is ObjectProxy) {
			arr = new ArrayCollection([obj]);
		}else{
			arr = obj as ArrayCollection;
		}
		return arr;
	}
	
  • Bookmark this page on Delicious
  • Bookmark this page on StumbleUpon
  • Digg this page on Digg
  • Submit this page on Reddit
  • Submit this page on Furl
  • Share this page on Facebook
  • Bookmark this page on Google
  • Bookmark this page on Yahoo
  • Search for links to this page on Technorati
  • Search for links to this page on IceRocket

Comments


Leave a comment (E-mail address never displayed)





2006-2009 @ SkyByte.net. All Rights Reserved xhtml 1.0 css