public function setBackground(color:Number):void {
canvas.setStyle("backgroundColor", color);
}
]]>
父应用:
import mx.managers.SystemManager;
import mx.events.FlexEvent;
private function initHandler(event:Event):void {
event.target.content.addEventListener(FlexEvent.APPLICATION_COMPLETE,
applicationCompleteHandler);
}
private function applicationCompleteHandler(event:Event):void {
event.target.application.setBackground(0xFFFF00);
}
]]>
提示:
Flex 2.0.1内建的特性创建一个模块应用,在运行时将几个.swf文件缝装在一起。在许多情况下,使用模块是更简单的方法。
Understanding Application Domains
一个应用域是运行在FlashPlayer中的分隔的一个应用?????????。在多数情况下,只有一个应用运行在FlashPlayer中,这时只有一个应用域。但当你在一个已存在的应用中载入附加的.swf文件时,你可能需要为附加的应用创建新的应用域。
All Flex and Flash applications are composed of collections of classes. An applica-
tion domain holds the collections of classes for an application or applications. When
just one application is running in Flash Player, the concept of an application domain
is practically a formality because you are guaranteed that an .swf will never contain
more than one definition for a class. However, when you load an additional .swf file,
there is a possibility that it will contain a definition for a class by the same name as
one that is already loaded from another .swf file. An application domain ensures that
within the domain there is only one definition for each class. Therefore, it has a set of
rules for determining how to choose between conflicting definitions if such a sce-
nario presents itself.
If an application is loaded into an application domain with a parent, it essentially
inherits all the class definitions from the parent application domain. The result is
that the child application domain cannot have class definitions for classes that are
otherwise defined in the parent application domain. For example, if you load one
Flex application .swf into another Flex application .swf with the default settings,
there would be two application domains but one would be a child of the other, and
all duplicate Flex framework classes from the child would be disregarded in favor of
the same classes from the parent application domain. This is often appropriate, and
it has several possible benefits:
* It uses less memory. If the duplicate classes were not disregarded, memory usage
would increase.
* Singleton manager classes are accessible to both the parent and the child applica-
tions (meaning that just one instance of the class is shared by parent and child
applications).
* Theoretically, it is possible to compile the child .swf files by excluding any dupli-
cate classes the child .swf would inherit at runtime from the parent application
domain. This would reduce the file size overhead in child .swf files.
Just as there are cases in which this default child domain behavior is useful, some-
times it works at cross purposes with the needs or requirements of a project. For
example, consider the scenario in which two applications are built using two classes
with the same name but very different implementations. If one is loaded into the
other, the child will not work as intended because that class will be discarded in the
child, and the parent version will be used in both applications. In such a case, it is
clear that there is a need to be able to completely partition the applications into sepa-
rate application domains. Separate application domains ensure that the sorts of con-
flicts just described don’t occur. However, it is important to use these sorts of
exclusive application domains only when necessary because they will increase mem-
ory usage.
第1种:被载入的.swf文件运行在一个新的应用域,作为已存在应用域的child。
第2种:被载入的.swf文件运行在一个新的应用域
第3种:一个.swf文件被载入到相同应用域。用于运行时共享库,当你想运行时载入字体和其它的assets库在主应用里使用时,它也是有用的。
例子:
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); 将当前应用域作为新应用域的父应用域
// context.applicationDomain = new ApplicationDomain();新建一个分离的独立的应用域
//// context.applicationDomain = ApplicationDomain.currentDomain; 使用当前的应用域
var request:URLRequest = new URLRequest("RuntimeLoadingExample.swf");
var loader:Loader = new Loader();
loader.load(request, context);
理解预加载器Understanding the Preloader
默认的,所有的Flex applications都有一个预加载器,通过一个进度条指示应用加载和初始化的进度。通常的,进度条注册一个或多个的侦听器,为preloader对象分发的一系列事件,以下是preloader的有效事件:
progress指示下载进度
complete指示下载完成
rslError指示运行时共享库不能被载入
rslProgress指示运行时共享库的下载进度
rslComplete指示运行时共享库的下载完成
initProgress指示应用正在初始化
initComplete指示应用已经初始化
一旦,system manager进入到第二帧,应用进行自身的创建和初始化。.....