Home > Adobe Flex > Flex Sub-applications, Sandboxes & SWFLoader (Part 1)

Flex Sub-applications, Sandboxes & SWFLoader (Part 1)

A few months ago, I embarked on a project for 24 Hour Fitness that involved something I had only heard about at the 2008 Adobe MAX conference in San Francisco – “flex sub-applications”. There, I attended a lecture by Alex Harui on Flex Framework Features to Support Large Applications (listen to the lecture here on Adobe TV). I must admit the lecture had probably put many to sleep, but I was fascinated by the concept and to this day (granted, MAX was just a few months ago) I believe this will become a very important topic to many as the complexity and possibilities available in large-scale Adobe Flex applications becomes ever apparent.

For this reason, I appended a “Part 1″ to the title of this article as I don’t know if I can squeeze my experience with sub-applications into just one writing and I certainly plan in the coming months to venture even farther into these murky waters.

I think Alex’s main point behind his lecture was to unveil the new Marshall Plan bundled with Flex 3.2 (released during MAX). But before I can describe what the Marshall Plan is, it’s important to know why it came about.

Most applications you’ll ever build in Flex are probably on the smaller scale, ranging from anywhere between a few hundred kilobytes (final SWF size) to several megabytes of compiled Flex code (including the Flex framework). This doesn’t include embedded images or other assets which could dramatically increase that size (I typically try very hard NOT to embed assets to keep the final SWF as lean as possible). Some applications could be significantly larger, spanning hundreds or thousands of commands (if you use Cairngorm or other such MVC architecture), classes and MXML.

It’s always very important to understand that the entire application frame of your final SWF will be downloaded to the client in one shot. This could be a lengthy wait for some and the solution has always been to break up that large application into pieces, or “modules” that could be loaded and unloaded during runtime.

The possibility of caching some code in the client’s Flash Player for re-use by other applications was also created by using Runtime Shared Libraries (RSL’s). But because of “full class integration” (the ability to reference classes in the RSL by classname), the RSL must be compiled with the same version of Flex as the main application. RSL’s also have the disadvantage of not being unloadable. Once an RSL has been loaded at the onset of application startup, it’s there to stay.

Modules are another example of re-using functionality. Modules are collections of classes compiled into a SWF and are loaded by ModuleLoader. Classes in modules are not directly referenced by the main application. Instead both refer to a shared interface (IDataGrid, for example). This is called “partial class integration”. Modules can also be unloaded and removed from memory. Unfortunately because the main application and module share at least some assets, modules, too must be compiled by the same version of Flex as the main application.

Which brings us to a new concept called “sub-applications”, released as a part of Flex 3.2 in November, 2008 at Adobe’s MAX conference in San Francisco. Sub-applications have NO class integration, which is needed to support multi-versioning .

Sub-applications are completely individual, separate applications (identified by the root tag), compiled into a SWF that is loaded by a parent application through the SWFLoader component (you can also use Loader and added the loader object as a child to SWFLoader).

Previously, Flex 2 also supported the concept of sub-applications in that you could use SWFLoader to load another SWF application. You could even access properties in the sub-application from the main application using the SystemManager class. Unfortunately, Flex 2 was only able to load the sub-application into the same “SecurityDomain” (or sandbox) as the parent application. By playing in the same sandbox, the sub-application could have unrestricted access to variables in the main application…an unwanted side-effect especially if the sub-app is untrusted (say, written by a third-party).

With Flex 3.2, you have a little more control over how the sub-application SWF is loaded, primarily through two properties of SWFLoader. One is trustContent (which existed in Flex 2) and the other is loadForCompatibility (new as of Flex 3.2). And the changes in the Flex source code revolving around the new loadForCompatibility feature really serve as the basis for the new Marshall Plan.

The trustContent property specifies whether the sub-application is loaded into the same SecurityDomain as the host. This property is defaulted to false, which means SWF content loaded from separate domains (xyz.com instead of abc.com) will load without error if the separate domain does not have a crossdomain.xml policy file declaring that your domain has rights to access its content. This is preferred behavior, however your parent application would not be able to access the SWF content (via SWFLoader.content). This property is directly tied to the SWFLoader.loaderContext.securityDomain property and can also be set manually via ActionScript.

Setting trustContent to true is equivalent to copying the loaded SWF to your own server and loading it from there. This is one way to get around any security sandbox restrictions you might experience, however I also noticed that it also can cause other complications, most notably with singleton’s like Cairngorm’s ServiceLocator (which I’ll discuss in a later post).

The loadForCompatibility property specifies whether the sub-application is loaded into a peer ApplicationDomain as the parent (when set to true), or into a child ApplicationDomain (when set to false). This flag only pertains to applications loaded within the same SecurityDomain (if trustContent == true).

Child ApplicationDomains inherit classes from the parent (like UIComponent, Container, etc). This can cause obvious problems if both applications were compiled with different versions of Flex. A child sub-application written in Flex 3.2 may not wish to inherit the UIComponent definition of its parent application that was written in Flex 4. The loadForCompatibility flag forces SWFLoader to load the sub-application into a separate ApplicationDomain (when true) which keeps the definitions for these classes separate. This is most needed for multi-versioned applications. This flag should only be set to true if you know both applications will always be compiled with the same version of Flex.

In my next article, I’ll discuss some of the pitfalls I ran into with sub-applications and specifically, Cairngorm-based sub-applications. Stay tuned!

Categories: Adobe Flex Tags:
  1. January 21st, 2025 at 06:58 | #1

    In this region, the fabric undergoes only elastic deformation.

  2. January 21st, 2025 at 07:32 | #2

    We keep hearing that one of the companies, say for example Apple, is down $9.75 or 7.46 per cent in after-hours trading and this takes 59.55 points off the Dow.

  3. January 21st, 2025 at 07:52 | #3

    Her earnest evaluations of places like Olive Garden, McDonald’s and Applebee’s have received her legions of followers.

  4. January 21st, 2025 at 07:58 | #4

    The Encyclopedia of Indianapolis.

  5. January 21st, 2025 at 08:24 | #5

    As a reputable company, they are recognized for offering a range of professional services from the development of security awareness & policy to the delivery of effective solutions including, secure content management, vulnerability assessment, perimeter security, risk, policy & compliance management, identity and access management.

  6. January 21st, 2025 at 09:23 | #6

    To find out why the Metropolitan may have run its course in only eight years, see the final section of our article.

  7. January 21st, 2025 at 10:29 | #7

    Instance: Many impartial hotels worldwide, like Resort Victory in the Philippines, use eZee FrontDesk to manage their day-to-day operations successfully.

  8. January 22nd, 2025 at 05:44 | #8

    Don’t ask “how are you doing,” ask as a substitute “what are you doing?

  9. January 22nd, 2025 at 12:43 | #9

    So not only do you get better value for your foreign exchange in Jaipur, but also the best exchange rates in the industry and at the same time transparency in transactions.

  10. January 23rd, 2025 at 03:07 | #10

    However, he generally loses his composure and will get in fights with other characters, and he may be shy round girls.

  11. January 23rd, 2025 at 04:43 | #11

    A 230-bhp model was a new Particular/Skylark option and normal for Sport­wagon, Skylark Customized, and LeSabres; all these offered the tuned unit at further value.

  12. January 23rd, 2025 at 05:31 | #12

    Centralization concerns due to Ripple Labs’ control.

  13. January 23rd, 2025 at 05:45 | #13

    On 26 Could 1945, the working firm resumed the Holzmarkt-Günterstal and Oberlinden-Littenweiler routes after repairing the tracks and overpass on the barely broken sections of the route.

  14. January 23rd, 2025 at 06:05 | #14

    Rear tire put on (1998-2000 fashions) inspired Volkswagen to situation new specs for rear wheel alignment.

  15. January 23rd, 2025 at 06:37 | #15

    Perhaps, this may even be a very good level to contemplate whether or not cell houses are worth shopping for or not.

  16. January 23rd, 2025 at 23:37 | #16

    At the point when common asset contributing, shares of mutual funds will fluctuate in quality.

  17. January 23rd, 2025 at 23:44 | #17

    Helo there, just bbecame alert tto your blokg throygh Google, aand found tha itt iis truly informative.
    I’m going to watdh outt forr brussels. I will aplpreciate iif yoou continue this iin future.
    Manyy peoople will bee benefitsd frm your writing.
    Cheers!

  18. January 23rd, 2025 at 23:50 | #18

    Hi, i thik thaat i noiced you visited mmy web site sso i came to return tthe want?.I
    aam attepting to tto find things tto enhance mmy wweb site!I suppose its adeqquate to use a feww of you concepts!!

  19. January 24th, 2025 at 02:22 | #19

    Effectively, GDP fluctuations affect supply and demand, which can lead to central banks reducing or rising curiosity rates, which in turn affects the nation’s forex worth!

  20. January 24th, 2025 at 05:26 | #20

    The infinite horizon tax hole gives the adjustment required to fulfill the inter-temporal finances constraint when it comes to a everlasting one-time change to projected path of main stability to GDP ratios.

  21. January 24th, 2025 at 05:27 | #21

    Password protection at different ranges limits the entry that workplace employees should the knowledge.

  22. January 24th, 2025 at 05:35 | #22

    Democratic Congressman John Lewis spoke alongside Barr at the dedication.

  23. January 24th, 2025 at 07:23 | #23

    If you’re struggling, consider debt negotiation – In case you are stretching to make your funds now, likelihood is things aren’t going to get any simpler.

  24. January 24th, 2025 at 07:29 | #24

    Simao additionally says Windstar has simply employed two new people to affix the sales crew-promoting them internally from the reservations crew.

  25. January 24th, 2025 at 07:29 | #25

    There is evidence that digital financial services can empower women to earn more and build assets, helping address that 35 of women worldwide-approximately 980 million-remain excluded from the formal financial system.

  26. January 24th, 2025 at 07:42 | #26

    In other words, it is easier to attract venture capital during the growth stage as compared to the seed stage.

  27. January 24th, 2025 at 08:48 | #27

    You’ve made some decent points there. I looked on the net for more info about the issue and found most individuals will go along with your views on this web site.

Comment pages
1 3 4 5 194
  1. No trackbacks yet.