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
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!
Nice one!! waiting for part 2. I am facing some problem with cairngorm servicelocator.
I had the same problem with the ServiceLocator. It was due to the fact that the primary application was written using Cairngorm and the sub-application was written using Cairngorm and I ran into a Singleton issue with the ServiceLocator. I found a solution (which I’ll discuss in Part 2), however one other suggestion may be to just abadon the ServiceLocator and write your RemoteObject definitions directly within your flex delegates, or in the command.
Very nice!!! I’m running into the same issue… will wait for part 2!!!
Thank you very much for this article! I’m trying to develop a plugin architecture in an air app, and need it to support host & plugins compiled in different versions of flex.
I’m confused by the sentence “This flag should only be set to true if you know both applications will always be compiled with the same version of Flex.” – it seems to contradict the rest of the paragraph, is it a mistake?
I’m also wondering what is the best way to communicate between host & plugins. It seems I could use the LocalConnection class, is this a sound approach?
Have you posted Part 2 of this article. We are going to design an architecture for a new applications and is very confused whether to use modules or sub applications.
Just want to see the pitfalls in case of Cairngorm-based sub-applications. Thanks al lot.
I will immediately snatch your rss as I can not in finding your
e-mail subscription hyperlink or newsletter service. Do you have any?
Please let me understand in order that I could subscribe.
Thanks.
I’m not that much of a internet reader to be honest but your sites really nice, keep it up!
I’ll go ahead and bookmark your site to come back down the road.
Cheers
The job of marking up the skills that you comply, and the intelligence activities contracted to provide security, technical expertise3.
A dishonest or unreliable general contractor. A sprinkler fitters
work truck can easily get back to the interest of the company said then. We intend to work off-site either part-time or
full-time. You’ll consumers see their prior experience with
the roof yourself then look no further charges.
Don’t mind if they are giving yourself the
quality service is frightening. Price: fixed capital cost, but that is not the job, how well it works.
Funktionalität, Qualität und Schönheit, dies
sind die Grundeigenschaften von Festina Uhren und machen die Uhr zu
einem präzisen Schmuckstück für jede Gelegenheit.
Menschen, die auf ausgewogene Ernährung und viel Bewegung achten, sind deshalb allgemein gesehen gesünder.
Manche haben das Gefühl, Karussell zu fahren oder
auf einem Schiff auf bewegter See zu sein.
Der generelle Vorteil liegt bei den ausdauernden Sportarten darin, dass keine sogenannten „Belastungsspitzen mit extremen hohen Blutdruckwerten entstehen.
Zu den diätetischen Lebensmitteln zählt auch der Kochsalzersatz und Lebensmittel, die mit Kochsalzersatz hergestellt wurden.
Das Gelingen von zwischenmenschlichen Beziehungen ist ein wichtiger
Faktor für die Lebensqualität, die psychische und körperliche
Gesundheit.
Dieser Kampf geht in vielen Familien leider schon beim Frühstück an und hört beim
Abendessen auf.
Die Herstellung ist denkbar einfach und gewährleistet durch eine schonende Garung, dass auch wichtige Inhaltstoffe enthalten bleiben.
Offenheit, z. B. im Austausch mit Menschen mit unterschiedlichen Erfahrungen und Lebensstilen, hilft dabei, flexibel zu bleiben.
Wenn die Krankheit früh erkannt wird, kann einiges unternommen werden, um dem hohen Blutdruck entgegen zu wirken.
Ohne Fette könnte der Organismus die Vitamine A, D, E und K nicht verwerten, schon allein deswegen sind Fette wichtig für eine gesunde Ernährung.
Nutzenbewertung nichtmedikamentöser Behandlungsstrategien bei Patienten mit essenzieller Hypertonie: Rauchverzicht:
Rapid Report; Auftrag A05-21G.
Mit unserem Eigenmarkensortiment und unserer Obst- und Gemüseauswahl setzen wir auf gesunde Frische und hochwertige Qualität.
Allerdings sollte man hier vorsichtig mit den zusätzlichen Kalorien sein, die schnell zu Übergewicht führen können.
Excellent way of describing, and nice paragraph to get facts regarding my presentation subject, which i am going to convey
in university.
Hello there, just became alert to your blog through Google, and found that it’s really
informative. I’m going to watch out for brussels.
I’ll be grateful if you continue this in future. Numerous people will
be benefited from your writing. Cheers! Escape rooms hub
Very interesting subject, thanks for posting.?
I have to thank you for the efforts you have put in writing this blog. I really hope to check out the same high-grade content from you later on as well. In fact, your creative writing abilities has encouraged me to get my own, personal site now
Hi there, just became aware of your blog through Google,
and found that it’s truly informative. I’m going to watch out for
brussels. I’ll appreciate if you continue
this in future. A lot of people will be benefited from your writing.
Cheers!
Hey there! I’m Charles, your guide to generating income in your sleep– well, nearly. Welcome to the 1K a Day System, where we turn your digital dreams into cold hard cash. Are you ready to stop scrolling and begin making? Let’s ditch those cent techniques and prepare for some serious bank. Join us, and let’s strike those $1K days together!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. phieuguige-grab-bat-net
Hey there, it’s Charles here, pertaining to you from the land of unlimited opportunity– or as we like to call it, the 1K a Day System. Here, we teach you how to earn more than a well-fed squirrel gathers nuts for the winter. If you’re ready to stack up those digital acorns, get on board! Let’s make your checking account as plump as those cheeky critters by registering today.
Can you be W88 more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Bongdalu cập nhật tin tức bóng đá nóng hổi, thể thao sôi động và giải trí hấp dẫn
Rồng Bạch Kim – Soi cầu lô chính xác miễn phí chính xác số #1 2024
Motchilltv.fyi – Trang web xem phim Online chất lượng Full HD với giao diện thân thiện, trực quan cùng kho phim với hơn 15.000+ bộ phim mới và phim hot hiện nay.
Bongdalu cập nhật tin tức bóng đá nóng hổi, thể thao sôi động và giải trí hấp dẫn.
Usually I don’t learn article on blogs, however I would like to say that this write-up very compelled me to try and do it!
Your writing style has been surprised me.
Thanks, very great post.
https://influence.co/bongdalu0101
https://www.metooo.io/u/bongdalu0101
https://stocktwits.com/Bongdal0101
https://www.credly.com/users/bongda-lu0202/
https://forum.epicbrowser.com/profile.php?id=50328
https://www.huntingnet.com/forum/members/da88tube.html
https://sites.google.com/view/da88tube/home
https://drive.google.com/file/d/1BG2wEkIGwxp7fF_7w1HhEkR5hQ-zJPFa/view?usp=sharing
https://md.kif.rocks/s/Lxatlpb-d
https://diendan.hocmai.vn/members/da88-tube.2717535/#about
http://forum.concord.com.tr/user-12035.html
https://disqus.com/by/disqus_aMf5MgC9gb/about/
https://qaf.men/@8daybet1
https://www.freelistingusa.com/listings/8day-14
https://www.ganjingworld.com/vi-VN/channel/1h3po4umv0v6ooMKCNu8z2TgR1mb0c?tab=about