Archive for February 16th, 2009

16
Feb

Declaration tag in Flex Gumbo

Flex Gumbo have added a new tag called declaration. The new tag has to be used in cases where you want to reference a component that is not part of the mx.core or classes that are not display objects.

For instance, when creating Cairngorm projects you need to set references in the entry point to your controller, services and view such as the following code:


	<view:MainApp />
	<control:Controller />
	<business:Services />

However, in Flex Gumbo classes that are not display objects needs to be placed in a a declarations tag. Change your code easily by placing your classes to the declaration tag as follow;


	<view:MainApp />
	<Declarations>
		<control:Controller />
		<business:Services />
	</Declarations>

Otherwise you will get the following runtime error message.


TypeError: Error #1034: Type Coercion failed: cannot convert com.domain.project.control::Controller@21cf9d61 to flash.display.DisplayObject.
	at mx.components::Group/itemAdded()[E:\dev\gumbo_alpha\frameworks\projects\flex4\src\mx\components\Group.as:752]
	at mx.components::Group/initializeChildrenArray()[E:\dev\gumbo_alpha\frameworks\projects\flex4\src\mx\components\Group.as:251]
	at mx.components::Group/commitProperties()[E:\dev\gumbo_alpha\frameworks\projects\flex4\src\mx\components\Group.as:267]
	at mx.core::UIComponent/validateProperties()[E:\dev\gumbo_alpha\frameworks\projects\framework\src\mx\core\UIComponent.as:6130]
	at mx.managers::LayoutManager/validateProperties()[E:\dev\gumbo_alpha\frameworks\projects\framework\src\mx\managers\LayoutManager.as:539]
	at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\gumbo_alpha\frameworks\projects\framework\src\mx\managers\LayoutManager.as:659]
	at Function/http://adobe.com/AS3/2006/builtin::apply()
	at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\gumbo_alpha\frameworks\projects\framework\src\mx\core\UIComponent.as:8849]
	at mx.core::UIComponent/callLaterDispatcher()[E:\dev\gumbo_alpha\frameworks\projects\framework\src\mx\core\UIComponent.as:8789]

Notice that I haven’t placed my view in the declaration tag, since my view is a Canvas component, which extends Container. So what?

Component that doesn’t implements the mx.core namespace has to go into the declaration tag, including all the Fx components, however Canvas extends Container which is part of mx.core so no need to place it in the declaration tag.

By the way, you may have the same issue with PureMVC projects. The view reference in your entry point may need to be placed in the declaration tag, as explained above.