tags:

views:

104

answers:

2

I received this warning when I migrated my application from flex 3 to flex 4:

components:MyApp is a module or application that is directly referenced. This will cause components:MyApp and all of its dependencies to be linked in with modules:searchModule. Using an interface is the recommended practice to avoid this. Unknown Flex Problem

MyApp is a class which extends the Application component and in the module named "searchModule" there's this line:

var parentApp:myApp = parentApplication as MyApp;

I then use the variable myApp to call methods defined in the MyApp class from within this module.

This warning is reported 10 times because I am doing the same in other modules.

I want to fix it but I don't understand the part "this will cause its dependencies to be linked in with modules" and how would I make an interface to avoid this? And why there wasn't a warning about it in flex 3?

Thanks in advance

+2  A: 

I'm guessing a bit, but...

The Flex Framework is one of those special Adobe-only libraries that can be cached by the Flex player. As such, with certain compile settings, the SWF from the compiler does not contain the Flex library. In lex 4, the framework is not compiled into your application SWf, resulting in significantly smaller application file size.

If you extend the Application class, which it sounds like you done, the compiler cannot count on your new "Application" being in the cached Flex Framework and therefore must compile your new class, and therefore the Application tag into your SWF. This is going to daisy chain significantly; as the Application tag does a lot of Flex Framework setup stuff.

I assume that is what the warning means in terms of dependencies.

Did you really extend Application with additional functionality? Or is "MyApp.mxml" just the name of the your main application file?

You might try this:

var parentApp:Application = parentApplication as Application;

I believe there is a FlexGlobals class introduced in Flex 4, which can also give you access to the top level Application.

In terms of using an interface. Interfaces are designed to help remove specific dependencies. You can create an interface for your new functionality of the new Application class and reference that instead.

var parentApp:myApp = parentApplication as IMyApp

Based on my interpertation of the messages you're seeing that may address the issue.

www.Flextras.com
The main application file is called main.mxml and instead of the root application tag I have this:<custom:MyApp xmlns:custom="components.*" ..........></custom:MyApp>And there's MyApp.cs which extends the Application, and there's methods I defined in this class to be called by the modules loaded by the main application, so in the module file I created the variable of type MyApp in order to access the methods of this class. If I casted the parentApplication to Application instead of MyApp as you suggested I won't have access to those methods.
Yasmine
I need to understand something, extending the Application is not a good thing to do and better use an Interface or just merge the flex framework into the application and this will solve this issue?
Yasmine
It is unusual to extend the Application class in practice; but I'm not sure I'd say it's inherently bad. It depends. Every decision constitutes some trade-offs. If I understand the warning, just create an interface w/ all your new methods and have your myApp class extend that interface. Whenever you convert 'Application' do so using the interface instead of the explicit class. Since you have a warning (not an error) you can also just ignore it.
www.Flextras.com