Loader 与SWFLoader 区别

在Flex中可以通过Loader和SWFLoader来进行swf和图像文件的加载。但是两者又有一些不同。

 

1.  Loader继承自Loader->DisplayObjectContainer-> InteractiveObject ->DisplayObject,但Loader 类会覆盖其继承的以下方法,因为 Loader 对象只能有一个子显示对象 - 其加载的显示对象。调用以下方法将引发异常:addChild()、addChildAt()、removeChild()、removeChildAt() 和 setChildIndex()。要删除被加载的显示对象,必须从其父 DisplayObjectContainer 子级数组中删除 Loader 对象。

 

SWFLoader继承自SWFLoader ->UIComponent ->FlexSprite ->Sprite ->DisplayObject,所以SWFLoader其实相当于一个容器,可以放置除加载资源的其他组件,而且你还可以删除加载资源。

 

2.Loader记载的资源文件不会自适应Loader的大小,SWFLoader加载的内容会缩放内容以适应 SWFLoader 控件的大小。所以在Loader加载时您可能需要为 Loader 对象定义蒙版,以防止将加载的内容(Loader 对象的子级)绘画到该蒙版之外的舞台部分中。

 

3.SWFLoader其实是对Loader的一种包装,所以自身内置了需要加载需要的功能,譬如load方法中可以直接传入要加载资源的url而不用传入URLRequest对象,自身就用loaderContext属性来进行设置等。

Adobe官方文档Comparing the SWFLoader and Loader controls一节中对其也有很好的描述:

 

The SWFLoader control has the following features:

 

Supports Flex styles and effects; the Loader class does not have any inherent support for styles and effects.

支持flex的样式和特效;而Loader类却不支持任何固有的样式和特效。

Lets you monitor the progress of a load inherently (if you use the Loader class, you have to first get a reference to a LoaderInfo object).

方便管理加载进度;如果使用Loader则首先要获取LoaderInfo引用。

Is a UIComponent. As a result, the SWFLoader control participates in the display list and adds children to the display list without having to write additional code.

是一个UIComponent组件。SWFLoader它自己管理了所有子显示对象,不需要添加多余的代码。

Resizes and scales the contents automatically.

自动缩放显示内容的大小。

Does not require that the SWF file be an instance of the Application class, it just checks if an Application exists, and handles sizing differently.

可以加载Application以外的实现类,如果检测到不是一个Application,会自动进行处理。

Can be multi-versioned. The Loader class does not have built-in support for multi-versioning.

可以处理不同的版本。Loader不支持加载不同的编译版本。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
11
11-20 162
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值