PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: emurphy on May 06, 2010, 12:39:44



Title: [Flex 4] AS code can't reference view component?
Post by: emurphy on May 06, 2010, 12:39:44
So I ported my project from Flex 3 to Flex 4. I'm trying to simply load a module in an application and setup its mediator to use it. I keep getting this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at mx.core::UIComponent/getStyle()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:10372]
   at spark.components::Label/createTextLinesFromTextBlock()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Label.as:831]
   at spark.components::Label/createTextLines()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Label.as:808]
   at spark.components::Label/http://www.adobe.com/2006/flex/mx/internal::composeTextLines()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Label.as:474]
   at spark.components.supportClasses::TextBase/measure()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\supportClasses\TextBase.as:533]
   at mx.core::UIComponent/measureSizes()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8042]
   at mx.core::UIComponent/validateSize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:7966]
   at mx.managers::LayoutManager/validateSize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:617]
   at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:709]
   at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]

I was reading on the adobe forum about this and they said in response to someones similar issue:
[http://forums.adobe.com/message/2792526#2792526]

The main point of modules is to make the main application SWF smaller.  When using modules you have to realize that any mention of a class in the application code links in those classes and all dependent classes.  We sort of assumed that folks knew that and have made changes to the styles system in Flex 4 that require that you know that.

And again, in reference to someones specific problem:

You are using the module class in the main app which sort of defeats the point of having a module as it will link testModule into the main app.  When that happens in Flex 4, the styles don't get set up properly.  You should use an interface instead of the module class.

The basic idea I gather is that you cant reference the module view component in any other code. Which brings me to a lot of problems and two questions:

1. Is that true?
2. If it is, how do I strongly type the view component in the mediator? Do I have to write an interface for every module?


Title: Re: [Flex 4] AS code can't reference view component?
Post by: emurphy on May 06, 2010, 01:17:10
I have it working now by using an interface for the module view component. The interface has to have a method for accessing everything in the view the mediator should have access to. Please someone tell me there is a better way?

Is there a way to include the classes used by a module in that module even if the view doesn't reference them? If so, I am assuming that the main app should have no knowledge of the mediators, commands, and proxies that the module contains. Which would mean the module view component would have to initialize them...and probably have its own facade. Can you have a module that isn't a core, ie, doesn't have a facade, and still get around this issue without using interfaces?


Title: Re: [Flex 4] AS code can't reference view component?
Post by: puremvc on May 08, 2010, 07:29:50
Its not a matter of whether you have a Facade in the module. You shouldn't be referencing classes that are defined in a module elsewhere in your app. Flex 4 is just enforcing a practice that should already be habit.

-=Cliff>


Title: Re: [Flex 4] AS code can't reference view component?
Post by: emurphy on May 10, 2010, 05:28:46
Yeah, I realized I was doing things wrong. I needed the ability to create and destroy items in a view stack and was using module loaders to do that. I found a better way. Thanks.