Attaching a flex multi-SWF file to applicatoin domain

Source: Internet
Author: User
Tags subdomain

Summary
When loading external SWF, we must understand the application domain ). From the official Adobe file, we can know that the application domain can split the classes in the same security domain, so that multiple definitions of a class can coexist, or let multiple sub-applications share the class definition of the parent application. Simply put, the application domain provides the partition function for the class definition.

Application domain
Multiple definitions of a class coexist: there are multiple classes in the memory with the same name, but different definitions are defined. Because they are in different application domains, they can coexist without mutual interference.

Shared parent application class definition: n sub-Applications reference the class definition provided by the same parent application. When the parent application is updated, the content referenced by the sub-application is also updated.

When loading an external SWF file, you can set three application domains for it:

1. Specify the loaded SWF to an existing application domain.

2. Specify the loaded SWF as a sub-application domain of an existing application domain.

3. Specify a brand new application domain for the loaded SWF.

Let's take a look at the illustration of the official document:

The figure contains four files, application1.swf1_module1.swf1_application2.swfand module3.swf. It has an independent application domain.

Independent domain. When the application definition is the same, several versions can be parallel

View plaincopy to clipboardprint?
01. var appdomaina: applicationdomain = new applicationdomain ();
02. var contexta: loadercontext = new loadercontext (false, appdomaina );
03. var loadera: loader = new loader ();
04. loadera. Load (New URLRequest ("application2.swf"), contexta );
VaR appdomaina: applicationdomain = new applicationdomain ();
VaR contexta: loadercontext = new loadercontext (false, appdomaina );
VaR loadera: loader = new loader ();
Loadera. Load (New URLRequest ("application2.swf"), contexta );

Share the domain and add a new class definition (RSL)

View plaincopy to clipboardprint?
01. var appdomainb: applicationdomain = applicationdomain. currentdomain;
02. var contextb: loadercontext = new loadercontext (false, appdomainb );
03. var loaderb: loader = new loader ();
04. loaderb. Load (New URLRequest ("module1.swf"), contextb );
VaR appdomainb: applicationdomain = applicationdomain. currentdomain;
VaR contextb: loadercontext = new loadercontext (false, appdomainb );
VaR loaderb: loader = new loader ();
Loaderb. Load (New URLRequest ("module1.swf"), contextb );

Subdomain: the class in the subdomain references the class definition in the parent application.

View plaincopy to clipboardprint?
01. var appdomainc: applicationdomain = new applicationdomain (applicationdomain. currentdomain );
02. var contextc: loadercontext = new loadercontext (false, appdomainc );
03. var loaderc: loader = new loader ();
04. loaderc. Load (New URLRequest ("module3.swf"), contextc );
VaR appdomainc: applicationdomain = new applicationdomain (applicationdomain. currentdomain );
VaR contextc: loadercontext = new loadercontext (false, appdomainc );
VaR loaderc: loader = new loader ();
Loaderc. Load (New URLRequest ("module3.swf"), contextc );

Notes
You cannot use an application domain when loading an image or a SWF file written in ActionScript 1.0/2.0, because the application domain can only be applied to ActionScript 3.0, we can use the "getdefinition" function to obtain the loaded class definitions.

Application domains form a tree structure, which is linked by "parentdomain", and the top layer is the system domain, which includes the built-in flash type, such as Sprite and textfield

When the class definition in a sub-application is loaded in the form of shared domain or subdomain, for example, the class to be loaded already defined in the parent application, the class definition is ignored.

The application domain is valid only in one security domain and cannot be used across domains.

More examples
Share domain Loading

-The hellow class from myapplication

-The swfhellow class from swf1

Subdomain Loading

-The hellow class from myapplication

-The swfhellow class from swf1 and swf2

Independent domain Loading

-The hellow class from myapplication

-The hellow class from swf1 and swf2

-The swfhellow class from swf1 and swf2

Todo questions
View plaincopy to clipboardprint?
01. function create (classname: string): Object
02 .{
03. var clazz: Class
04. = Class (applicationdomain. currentdomain. getdefinition (classname );
05. Return new clazz ();
06 .}
Function create (classname: string): Object
{
VaR clazz: Class
= Class (applicationdomain. currentdomain. getdefinition (classname );
Return new clazz ();
}

When we define the tool method create in the sub-application, in which applicationdomain. currentdomain is the parent application's currentdomain or the current currentdomain?

References
Http://blogs.adobe.com/rgonzalez/2006/06/applicationdomain.html

Http://ghalex.com/blog/application-domains-in-flex

Http://livedocs.adobe.com/flex/3/html/help.html? Content1_18_client_system_environment_5.html

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/rcom10002/archive/2010/03/02/5340269.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.