Flex多SWF文件加载之Applicatoin Domain
2010-06-26 15:04
363 查看
概要
当我们加载外部swf时,必须要了解应用程序域(ApplicationDomain)。从Adobe官方文件中,我们可以得知应用程序域能够把处于同一个安全域(Security
Domain)中的类分离开,这样就可以让一个类的多个定义共存,或是让多个子应用来共享父应用的类定义。简单点理解就是应用程序域为类定义提供了分区功
能。
应用程序域
一个类的多个定义共存:内存中有多个类,它们名称相同,但定义不同定义,由于处于不同的应用程序域,所以互不干扰,得以共存。子应用共享父应用的类定义:N个子应用引用同一个父应用的所提供的类定义,当父应用更新时,子应用所引用的内容也会随之更新。
当加载外部swf文件时,可以为其设置三种应用程序域:
一、将加载的swf指定至一个既存的应用程序域中。
二、将加载的swf指定为一个既存的应用程序域的子应用程序域。
三、为加载的swf指定一个全新的应用程序域。
我们先来看一下官方文档的说明图:
![](http://hi.csdn.net/attachment/201006/26/0_1277535256TX61.gif)
图中共有四个文件,分别为application1.swf、module1.swf、application2.swf和
module3.swf。module1.swf、application2.swf和module3.swf均被application1.swf加
载,其中module1.swf与application1.swf属于同一个域,module3.swf被划分至application1.swf的子
应用程序域,最后是application2.swf,它完全拥有一个独立的应用程序域。
独立域,在应用定义相同的情况下,可以使几个版本并行
var appDomainA:ApplicationDomain = new ApplicationDomain(); var contextA:LoaderContext = new LoaderContext(false, appDomainA); var loaderA:Loader = new Loader(); loaderA.load(new URLRequest("application2.swf"), contextA);
共享域,增加新的类定义(RSL)
var appDomainB:ApplicationDomain = ApplicationDomain.currentDomain; var contextB:LoaderContext = new LoaderContext(false, appDomainB); var loaderB:Loader = new Loader(); loaderB.load(new URLRequest("module1.swf"), contextB);
子域,子域中的类引用父应用中的类定义
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);
注意事项
加载图片或是用ActionScript 1.0/2.0编写的SWF文件时,不可以使用应用程序域,因为应用程序域只能应用于ActionScript
3.0,我们可以通过函数“getDefinition”来获取已经加载的类定义
应用程序域之间形成的是一个树形结构,它们之间靠“parentDomain”来链接,而最顶层是系统域(system
domain),它包括了Flash内置类型,如Sprite、Textfield等
当一个子应用中的类定义无论是以共享域还是子域的形式被加载,如过发现父应用中已经定义了的这个即将被加载的类,那么这个类定义的加载被忽略
应用程序域仅在一个安全域中有效,它不允许跨域使用
更多例子
共享域加载- the HelloW class from MyApplication
- the SWFHelloW class from SWF1
![](http://hi.csdn.net/attachment/201006/26/0_12775356082TO4.gif)
子域加载
- the HelloW class from MyApplication
- the SWFHelloW class from SWF1 and SWF2
![](http://hi.csdn.net/attachment/201006/26/0_1277535673g8cJ.gif)
独立域加载
- the HelloW class from MyApplication
- the HelloW class from SWF1 and SWF2
- the SWFHelloW class from SWF1 and SWF2
![](http://hi.csdn.net/attachment/201006/26/0_1277535736ATaA.gif)
TODO疑问
function create(className:String):Object { var clazz:Class = Class(ApplicationDomain.currentDomain.getDefinition(className); return new clazz(); }
当我们在子应用中定义了工具方法create,其中的ApplicationDomain.currentDomain是父应用的
currentDomain,还是当前的currentDomain?
参考文档
http://blogs.adobe.com/rgonzalez/2006/06/applicationdomain.htmlhttp://ghalex.com/blog/application-domains-in-flex
http://livedocs.adobe.com/flex/3/html/help.html?content=18_Client_System_Environment_5.html
相关文章推荐
- Flex多SWF文件加载之Applicatoin Domain
- Flex中采用主SWF文件加载子SWF文件中添加了Chart后,导致at mx.charts.chartClasses::ChartBase/initStyles()异常的问题解决方法
- [reproduce]How to Create Domain in Windows Server 2012.
- Unable to load native-hadoop library for your platform... using builtin-java classes where applica
- [cross domain] four approachs to cross domain in javascript
- Flash / Flex Tutorial - How to Create a crossdomain.xml file
- How to embed VideoIO in your Flex/Flash application?
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicabl
- How to use the new CSS syntax in Flex 4
- A Way to implement Abstract Class In Flex
- VS2010中调试Silverlight Applicatoin时出现Bug
- How to set up a domain environment in Hyper-V
- VS2010中调试Silverlight Applicatoin时出现Unable to start debugging的Bug.
- Adding links to a Panel container’s status text in Flex
- 6 ways/effects that response to user’s event in Flex
- 在Flex加载并显示swf文件(flash9)
- Flash / Flex Tutorial - How to Create a crossdomain.xml file
- Passing Domain Credentials in C# to a WebBrowser Control in .Net WinForms Applications(winform中传递域认)
- Flash / Flex Tutorial – How to Create a crossdomain.xml file
- How to install FlexPMD in Flex Builder 4.5