0
votes

Hello i'm migration flex 3 to flex 4 and i have 1 warning and i try to fix it but nothing work.

The warning is: data binding will not be able to detect assignments to toplevelapplication

In flex 3 i had application.Application and now i have FlexGlobals.topLevelApplication

I have 1400 FlexGlobals.topLevelApplication and +- 150 .AS files.

I tried to use Application(FlexGlobals.topLevelApplication), mainAPP(FlexGlobals.topLevelApplication), and nothing works, The only think that clean the warning is if i add [Bindable] public var myApplication:Object = FlexGlobals.topLevelApplication; to all the .AS files but when i run the project and try to log in the application i have Action Script Errors

Error #1009: Cannot access a property or method of a null object reference.

1
1400 references to topLevelApplication sounds like you may have a problem with the use of encapsulation in your code base. - JeffryHouser

1 Answers

0
votes

You're right. The clean way to access the Application is via FlexGlobals.topLevelApplication.

[Bindable]
public var app:mainApp = mainApp(FlexGlobals.topLevelApplication); // fail fast to find erros

Should to the work, if that is not the case, you seem to access that instance too early. You should bootstrap the Application (and move on from there) after FlexEvent.CREATION_COMPLETE has been dispatched. Also, i suggest that if you introduce a field in your classes like

private const app:mainApp = mainApp(FlexGlobals.topLevelApplication); // fail fast to find errors

protected final get app():mainApp { return app; }

to access the field cleanly in your application and avoid too many heavy dependencies to you application.

PS: Class names, even if suffixed .mxml should start with a capital letter.