Home > Flex Gotchas > SystemManager.application == null using SWFLoader or Loader

SystemManager.application == null using SWFLoader or Loader

So you need access to the application property inside the system manager you just loaded using SWFLoader or Loader huh?

There are two options:

1. Listen for the FlexEvent.APPLICATION_COMPLETE event on the System manager after the loader fires the Event.INIT event.

However, that sucks if you need access to the application before it has finished its construction.

While it isn’t ideal for my situation (I wanted access to the application before the initialize event was fired), I was able to get hold of the application after the initialize event had been fired, but before the creation complete event had been fired.

2. Listen for the Event.ENTER_FRAME event on the system manager, and check if the application property is not null. Tada. Crappy I know, but what can you do?

Also, remove the event listener once you have access to the application (unless you want it?).

Advertisements
  1. Mikko Pukki
    November 6, 2009 at 8:25 AM

    Hi,

    We have an application witch uses external components that are published from
    Flash and that works fine. We decided that we could try using also components
    compiled with Flex. After noticed that for some reason Application is wrapped with SystemManager we noticed that it has public property application. However it is null.. After a while I found this site (and some others too) describing the behavior, and tried to add listener for FlexEvent.APPLICATION_COMPLETE. All goes fine, except that event is never fired.

    We also tried adding ENTER_FRAME listener for SystemManager that is the target’s content in the EVENT.LOADED listener, but there SystemManager’s application is still null and wont change. Any idea what would be wrong? We are using Flash Builder 4 Beta 2 with 4.0.0 sdk

    • roustalski
      November 6, 2009 at 9:38 PM

      The component doesn’t start its initialization process until you add it to the display list somewhere. Have you done an addElement() call on the loader where it is supposed to be seen in the view?

  2. roustalski
    November 9, 2009 at 7:32 AM

    Ah, you said the swf you are loading is published from flash. So is the swf you are loading a flex application or a flash application?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: