用于 Adobe® Flash® Platform 的 ActionScript® 3.0 参考
主页  |  隐藏包列表和类列表 |   |   |  新增内容  |  索引  |  附录  |  为什么显示为英语?
过滤条件: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隐藏过滤条件
flash.display 

Loader  - AS3

x

顶级
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

语言元素

全局常量
全局函数
运算符
语句、关键字和指令
特殊类型

附录

新增内容
编译器错误
编译器警告
运行时错误
迁移到 ActionScript 3
支持的字符集
仅适用于 MXML 的标签
Motion XML 元素
Timed Text 标记
不推荐使用的元素的列表
AccessibilityImplementation 常量
如何使用 ActionScript 示例
法律声明
flash.display
public class Loader
继承Loader Inheritance DisplayObjectContainer Inheritance InteractiveObject Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object
子类 AVLoader, FlexLoader

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

Loader 类可用于加载 SWF 文件或图像(JPG、PNG 或 GIF)文件。使用 load() 方法来启动加载。被加载的显示对象将作为 Loader 对象的子级添加。

使用 URLLoader 类加载文本或二进制数据。

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

iOS 注意事项

在 iOS 上的 AIR 应用程序中,只能从应用程序包加载包含 ActionScript 的 SWF 文件。此限制针对的是任何 ActionScript,如为 ActionScript 导出类名称的资源。若想加载 SWF 文件,加载的 SWF 必须与父 SWF 使用相同的应用程序域,如下例所示:

 var loader:Loader = new Loader();
 var url:URLRequest = new URLRequest("swfs/SecondarySwf.swf");
 var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
 loader.load(url, loaderContext);

此外,在 iOS 上,您不能在加载包含任何 ActionScript 字节码 (ABC) 的 SWF 文件之后卸载它然后再重新加载它。如果您试图这样做,运行时会引发错误 3764。

在 AIR 3.6 之前,无论是从应用程序包还是通过网络加载 SWF 文件,只能加载不包含 ActionScript 字节代码的 SWF 文件。若想使用包含 ActionScript 的外部 SWF 文件,可用一种替代方法,即创建一个 SWC 库,然后将其链接到您的主 SWF。

AIR 3.7 及更高版本支持加载外部托管的二级 SWF。有关此功能的详细说明可以在此处找到。

当应用程序运行在 iOS 模拟器中(ipa-test-interpreter-simulator 或 ipa-debug-interpreter-simulator)或解释器模式下(ipa-test-interpreter 或 ipa-debug-interpreter)时,这些 iOS 限制不适用。

Loader 安全性

在使用 Loader 类时,请考虑 Flash Player 和 Adobe AIR 的安全模型:

  • 您可以加载来自任何可访问源的内容。
  • 如果执行调用的 SWF 文件位于网络沙箱中并且要加载的文件是本地的,则不允许加载。
  • 如果加载的内容为用 ActionScript 3.0 编写的 SWF 文件,那么除非可以通过调用加载的内容文件中的 System.allowDomain()System.allowInsecureDomain() 方法来允许跨脚本排列,否则另一个安全沙箱中的 SWF 文件不能对它执行跨脚本操作。
  • 如果被加载的内容为 AVM1 SWF 文件(用 ActionScript 1.0 或 2.0 编写),则 AVM2 SWF 文件(用 ActionScript 3.0 编写)不能对它执行跨脚本操作。但是,可以通过使用 LocalConnection 类在两个 SWF 文件之间实现通信。
  • 如果加载的内容为图像,则安全沙箱之外的 SWF 文件将无法访问其数据,除非该 SWF 文件的域包含在该图像的原始域上的 URL 策略文件中。
  • 在只能与本地文件系统的内容交互的沙箱中的影片剪辑不能对只能与远程内容交互的沙箱中的影片剪辑使用脚本,反之亦然。
  • 无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。

但在 AIR 中,application 安全沙箱中的内容(使用 AIR 应用程序安装的内容)不受这些安全限制的约束。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性

当从不受信任的源(如除 Loader 对象的根 SWF 文件以外的域)加载 SWF 文件时,您可能需要为 Loader 对象定义蒙版,以防止将加载的内容(Loader 对象的子级)绘画到该蒙版之外的舞台部分中,如以下代码所示:

 import flash.display.*;
 import flash.net.URLRequest;
 var rect:Shape = new Shape();
 rect.graphics.beginFill(0xFFFFFF);
 rect.graphics.drawRect(0, 0, 100, 100);
 rect.graphics.endFill();
 addChild(rect);
 var ldr:Loader = new Loader();
 ldr.mask = rect;
 var url:String = "http://www.unknown.example.com/content.swf";
 var urlReq:URLRequest = new URLRequest(url);
 ldr.load(urlReq);
 addChild(ldr);
 

注意:App Transport Security(应用程序传输安全性)是在 Apple iOS9 中引入的,它不允许应用程序和 Web 服务之间的连接不安全。鉴于应用程序传输安全性会改变所有通过 Loader 与不安全网站建立的连接,URLLoader 将停止使用而不再起作用。请通过在应用程序中为 Info.plist 添加关键字来指定默认行为的例外情况。

要完全关闭此功能,可以在您的 Info.plist 中添加以下内容,工作方式就会像以前一样。

     <key>NSAppTransportSecurity</key>
               <dict>
                   <key>NSAllowsArbitraryLoads</key><true/>
               </dict>
  

请通过在应用程序中为应用程序描述符的 InfoAdditions 标签添加关键字来指定默认行为的例外情况。

  <iPhone>
  <InfoAdditions>
                   <![CDATA[
                          <key>NSAppTransportSecurity</key>
                              <dict>
                                        <key>NSExceptionDomains</key>
                              <dict>
                                       <key>www.example.com</key>
                              <dict>
                                     <!--Include to allow subdomains-->
                                     <key>NSIncludesSubdomains</key>
                                     <true/>
                                     <!--Include to allow HTTP requests-->
                                     <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                                     <true/>
                                      <!--Include to specify minimum TLS version-->
                                      <key>NSTemporaryExceptionMinimumTLSVersion</key>
                                      <string>TLSv1.1</string>
                              </dict>
                              </dict>
                              </dict>
                  ]]>
         </InfoAdditions>
  </iPhone>
  

查看示例

相关 API 元素



公共属性
 属性由以下参数定义
 InheritedaccessibilityImplementation : AccessibilityImplementation
InteractiveObject 实例的当前辅助功能实现 (AccessibilityImplementation)。
InteractiveObject
 InheritedaccessibilityProperties : AccessibilityProperties
此显示对象的当前辅助功能选项。
DisplayObject
 Inheritedalpha : Number
表示指定对象的 Alpha 透明度值。
DisplayObject
 InheritedblendMode : String
BlendMode 类中的一个值,用于指定要使用的混合模式。
DisplayObject
 InheritedblendShader : Shader
[只写] 设置用于混合前景和背景的着色器。
DisplayObject
 InheritedcacheAsBitmap : Boolean
如果设置为 true,则 Flash 运行时将缓存显示对象的内部位图表示形式。
DisplayObject
 Inherited    cacheAsBitmapMatrix : Matrix
如果为非 null,则 Matrix 对象会定义显示对象在 cacheAsBitmap 设置为 true 时的呈现方式。
DisplayObject
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  content : DisplayObject
[只读] 包含使用 load() 或 loadBytes() 方法加载的 SWF 文件或图像(JPG、PNG 或 GIF)文件的根显示对象。
Loader
  contentLoaderInfo : LoaderInfo
[只读] 返回与正在加载的对象相对应的 LoaderInfo 对象。
Loader
 InheritedcontextMenu : NativeMenu
指定与此对象相关联的上下文菜单。
InteractiveObject
 InheriteddoubleClickEnabled : Boolean
指定此对象是否接收 doubleClick 事件。
InteractiveObject
 Inheritedfilters : Array
包含当前与显示对象关联的每个滤镜对象的索引数组。
DisplayObject
 InheritedfocusRect : Object
指定此对象是否显示焦点矩形。
InteractiveObject
 Inheritedheight : Number
表示显示对象的高度,以像素为单位。
DisplayObject
 InheritedloaderInfo : LoaderInfo
[只读] 返回一个 LoaderInfo 对象,其中包含加载此显示对象所属的文件的相关信息。
DisplayObject
 Inheritedmask : DisplayObject
调用显示对象被指定的 mask 对象遮罩。
DisplayObject
 InheritedmetaData : Object
如果元数据是通过 PlaceObject4 标记与此 DisplayObject 的实例一起存储在 SWF 文件中的,则获取 DisplayObject 实例的元数据对象。
DisplayObject
 InheritedmouseChildren : Boolean
确定对象的子级是否支持鼠标或用户输入设备。
DisplayObjectContainer
 InheritedmouseEnabled : Boolean
指定此对象是否接收鼠标或其他用户输入、消息。
InteractiveObject
 InheritedmouseX : Number
[只读] 表示此鼠标或用户输入设备位置的 x 坐标,以像素为单位。
DisplayObject
 InheritedmouseY : Number
[只读] 表示此鼠标或用户输入设备位置的 y 坐标,以像素为单位。
DisplayObject
 Inheritedname : String
表示 DisplayObject 的实例名称。
DisplayObject
 InheritedneedsSoftKeyboard : Boolean
指定当该 InteractiveObject 实例获得焦点时,是否显示虚拟键盘(显示在屏幕上的软键盘)。
InteractiveObject
 InheritednumChildren : int
[只读] 返回此对象的子项数目。
DisplayObjectContainer
 InheritedopaqueBackground : Object
指定显示对象是否由于具有某种背景颜色而不透明。
DisplayObject
 Inheritedparent : DisplayObjectContainer
[只读] 表示包含此显示对象的 DisplayObjectContainer 对象。
DisplayObject
 Inheritedroot : DisplayObject
[只读] 对于加载的 SWF 文件中的显示对象,root 属性是此 SWF 文件所表示的显示列表树结构部分中的顶级显示对象。
DisplayObject
 Inheritedrotation : Number
表示 DisplayObject 实例距其原始方向的旋转程度,以度为单位。
DisplayObject
 InheritedrotationX : Number
表示 DisplayObject 实例相对于 3D 父容器距离其原始方向的 x 轴旋转(以度为单位)。
DisplayObject
 InheritedrotationY : Number
表示 DisplayObject 实例相对于 3D 父容器距离其原始方向的 y 轴旋转(以度为单位)。
DisplayObject
 InheritedrotationZ : Number
表示 DisplayObject 实例相对于 3D 父容器距离其原始方向的 z 轴旋转(以度为单位)。
DisplayObject
 Inheritedscale9Grid : Rectangle
当前有效的缩放网格。
DisplayObject
 InheritedscaleX : Number
表示从注册点开始应用的对象的水平缩放比例(百分比)。
DisplayObject
 InheritedscaleY : Number
表示从对象注册点开始应用的对象的垂直缩放比例(百分比)。
DisplayObject
 InheritedscaleZ : Number
表示从对象的注册点开始应用的对象的深度缩放比例(百分比)。
DisplayObject
 InheritedscrollRect : Rectangle
显示对象的滚动矩形范围。
DisplayObject
 Inherited    softKeyboard : String
控制软键盘的外观。
InteractiveObject
 InheritedsoftKeyboardInputAreaOfInterest : Rectangle
定义当显示软键盘时应在屏幕上保留的区域(在 iOS 上不支持)。
InteractiveObject
 Inheritedstage : Stage
[只读] 显示对象的舞台。
DisplayObject
 InheritedtabChildren : Boolean
确定对象的子项是否支持 Tab 键。
DisplayObjectContainer
 InheritedtabEnabled : Boolean
指定此对象是否遵循 Tab 键顺序。
InteractiveObject
 InheritedtabIndex : int
指定 SWF 文件中的对象按 Tab 键顺序排列。
InteractiveObject
 InheritedtextSnapshot : flash.text:TextSnapshot
[只读] 返回此 DisplayObjectContainer 实例的 TextSnapshot 对象。
DisplayObjectContainer
 Inheritedtransform : flash.geom:Transform
一个对象,具有与显示对象的矩阵、颜色转换和像素范围有关的属性。
DisplayObject
  uncaughtErrorEvents : UncaughtErrorEvents
[只读] 在此 Loader 对象加载的 SWF 中发生未处理错误时调度 uncaughtError 事件的对象。
Loader
 Inheritedvisible : Boolean
显示对象是否可见。
DisplayObject
 Inheritedwidth : Number
表示显示对象的宽度,以像素为单位。
DisplayObject
 Inheritedx : Number
表示 DisplayObject 实例相对于父级 DisplayObjectContainer 本地坐标的 x 坐标。
DisplayObject
 Inheritedy : Number
表示 DisplayObject 实例相对于父级 DisplayObjectContainer 本地坐标的 y 坐标。
DisplayObject
 Inheritedz : Number
表示 DisplayObject 实例相对于 3D 父容器沿 z 轴的 z 坐标位置。
DisplayObject
公共方法
 方法由以下参数定义
  
创建一个可用于加载文件(如 SWF、JPEG、GIF 或 PNG 文件)的 Loader 对象。
Loader
 Inherited
将一个 DisplayObject 子实例添加到该 DisplayObjectContainer 实例中。
DisplayObjectContainer
 Inherited
将一个 DisplayObject 子实例添加到该 DisplayObjectContainer 实例中。
DisplayObjectContainer
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
 Inherited
表示安全限制是否会导致出现以下情况:在列表中忽略了使用指定 point 点调用 DisplayObjectContainer.getObjectsUnderPoint() 方法时返回的所有显示对象。
DisplayObjectContainer
  
取消当前正在对 Loader 实例执行的 load() 方法操作。
Loader
 Inherited
确定指定显示对象是 DisplayObjectContainer 实例的子项还是该实例本身。
DisplayObjectContainer
 Inherited
将事件调度到事件流中。
EventDispatcher
 Inherited
getBounds(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。
DisplayObject
 Inherited
返回位于指定索引处的子显示对象实例。
DisplayObjectContainer
 Inherited
返回具有指定名称的子显示对象。
DisplayObjectContainer
 Inherited
返回 DisplayObject 的 child 实例的索引位置。
DisplayObjectContainer
 Inherited
返回对象的数组,这些对象位于指定点下,并且是该 DisplayObjectContainer 实例的子项(或孙子项,依此类推)。
DisplayObjectContainer
 Inherited
getRect(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形根据 targetCoordinateSpace 参数定义的坐标系定义显示对象的边界,但不包括形状上的任何笔触。
DisplayObject
 Inherited
将 point 对象从舞台(全局)坐标转换为显示对象的(本地)坐标。
DisplayObject
 Inherited
将二维点从舞台(全局)坐标转换为三维显示对象的(本地)坐标。
DisplayObject
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
表示对象是否已经定义了指定的属性。
Object
 Inherited
计算显示对象的边框,以确定它是否与 obj 显示对象的边框重叠或相交。
DisplayObject
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
计算显示对象,以确定它是否与 x 和 y 参数指定的点重叠或相交。
DisplayObject
 Inherited
表示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
  
load(request:URLRequest, context:LoaderContext = null):void
将 SWF、JPEG、渐进式 JPEG、非动画 GIF 或 PNG 文件加载到此 Loader 对象的子对象中。
Loader
  
loadBytes(bytes:ByteArray, context:LoaderContext = null):void
从 ByteArray 对象中所存储的二进制数据中加载。
Loader
  
    loadFilePromise(promise:IFilePromise, context:LoaderContext = null):void
加载 IFilePromise 实例。
Loader
 Inherited
将三维显示对象的(本地)坐标的三维点转换为舞台(全局)坐标中的二维点。
DisplayObject
 Inherited
将 point 对象从显示对象的(本地)坐标转换为舞台(全局)坐标。
DisplayObject
 Inherited
表示指定的属性是否存在、是否可枚举。
Object
 Inherited
从 DisplayObjectContainer 实例的子列表中删除指定的 child DisplayObject 实例。
DisplayObjectContainer
 Inherited
从 DisplayObjectContainer 的子列表中指定的 index 位置删除子 DisplayObject。
DisplayObjectContainer
 Inherited
removeChildren(beginIndex:int = 0, endIndex:int = 0x7fffffff):void
从 DisplayObjectContainer 实例的子级列表中删除所有子 DisplayObject 实例。
DisplayObjectContainer
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
 Inherited
显示虚拟键盘。
InteractiveObject
 Inherited
更改现有子项在显示对象容器中的位置。
DisplayObjectContainer
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
对源起于此对象的所有 MovieClip 递归停止时间轴执行。
DisplayObjectContainer
 Inherited
交换两个指定子对象的 Z 轴顺序(从前到后顺序)。
DisplayObjectContainer
 Inherited
swapChildrenAt(index1:int, index2:int):void
在子级列表中两个指定的索引位置,交换子对象的 Z 轴顺序(前后顺序)。
DisplayObjectContainer
 Inherited
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
  
删除此 Loader 对象中使用 load() 方法加载的子项。
Loader
  
尝试卸载子 SWF 文件内容并停止执行已加载的 SWF 文件中的命令。
Loader
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何祖代为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件 摘要 由以下参数定义
 Inherited[广播事件] Flash Player 或 AIR 应用程序获得操作系统焦点并变为活动状态时将调度此事件。EventDispatcher
 Inherited将显示对象添加到显示列表中时调度。DisplayObject
 Inherited在将显示对象直接添加到舞台显示列表或将包含显示对象的子树添加至舞台显示列表中时调度。DisplayObject
 Inherited当用户从文本上下文菜单中选择“清除”(或“删除”)时调度。InteractiveObject
 Inherited用户在同一 InteractiveObject 上按下并释放用户指针设备的主按钮时调度。InteractiveObject
 Inherited
    contextMenu
当用户手势触发 AIR 应用程序中与此交互式对象相关联的上下文菜单时调度。InteractiveObject
 Inherited在用户为复制操作激活特定于平台的加速键组合或从文本上下文菜单中选择“复制”时调度。InteractiveObject
 Inherited在用户为剪切操作激活特定于平台的加速键组合或从文本上下文菜单中选择“剪切”时调度。InteractiveObject
 Inherited[广播事件] Flash Player 或 AIR 应用程序失去操作系统焦点并变为非活动状态时将调度此事件。EventDispatcher
 Inherited如果 InteractiveObject 的 doubleClickEnabled 标志设置为 true,当用户在该对象上快速连续按下两次并释放指针设备的主按钮时调度。InteractiveObject
 Inherited[播放事件] 播放头进入新帧时调度。DisplayObject
 Inherited[广播事件] 播放头退出当前帧时调度。DisplayObject
 Inherited显示对象获得焦点后调度。InteractiveObject
 Inherited显示对象失去焦点后调度。InteractiveObject
 Inherited[广播事件] 在帧显示对象的构造函数运行之后但在帧脚本运行之前调度。DisplayObject
 Inherited当用户使用 InteractiveObject 实例沿触摸面边缘创建接触点时调度(如在 Siri Remote for Apple TV 上沿触摸面边缘轻击)。有些设备也可能将这种接触解释为多个触摸事件的组合。InteractiveObject
 Inherited当用户在启用触摸设备上的同一 InteractiveObject 实例上按下两个接触点时(例如,在配有触摸屏的移动电话或平板电脑上的显示对象上按下和释放两个手指)调度。InteractiveObject
 Inherited当用户在启用触摸的设备上的 InteractiveObject 实例上移动接触点时(例如,在配有触摸屏的移动电话或平板电脑上的显示对象上从左向右移动手指)调度。InteractiveObject
 Inherited当用户在接触点处使用 InteractiveObject 实例执行旋转手势时(例如,将两个手指放在屏幕上,然后在配有触摸屏的移动电话或平板电脑上的显示对象上旋转这两个手指)调度。InteractiveObject
 Inherited当用户在接触点处使用 InteractiveObject 实例执行滑动手势(例如,在配有触摸屏的移动电话或平板电脑上用三根手指触摸屏幕,然后在一个显示对象上平行移动这三根手指)时调度。InteractiveObject
 Inherited当用户使用 InteractiveObject 实例创建接触点,然后点击启用触屏的设备时(例如,将几个手指放在显示对象上以打开菜单,然后点击一个手指在配有触摸屏的移动电话或平板电脑上选择一个菜单项)调度。InteractiveObject
 Inherited当用户在接触点处使用 InteractiveObject 实例执行缩放手势操作时(例如,将两个手指放在屏幕上,然后在配有触摸屏的移动电话或平板电脑上的显示对象上快速分开手指)调度。InteractiveObject
 Inherited此事件被调度到任何支持使用 IME 进行内联输入的客户端应用程序InteractiveObject
 Inherited用户按下某个键时调度。InteractiveObject
 Inherited用户尝试使用键盘导航更改焦点时调度。InteractiveObject
 Inherited用户释放某个键时调度。InteractiveObject
 Inherited当用户在同一 InteractiveObject 上按下并释放用户指针设备的中间按钮时调度。InteractiveObject
 Inherited当用户在 InteractiveObject 实例上按下指针设备的中间按钮时调度。InteractiveObject
 Inherited当用户在 InteractiveObject 实例上释放指针设备按钮时调度。InteractiveObject
 Inherited当用户在 InteractiveObject 实例上按下指针设备按钮时调度。InteractiveObject
 Inherited用户尝试使用指针设备更改焦点时调度。InteractiveObject
 Inherited用户移动 InteractiveObject 上的指针设备时调度。InteractiveObject
 Inherited用户将指针设备从 InteractiveObject 实例上移开时调度。InteractiveObject
 Inherited用户将指针设备移动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited当用户在 InteractiveObject 实例上释放指针设备按钮时调度。InteractiveObject
 Inherited当鼠标滚轮滚动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited当用户释放拖动手势时由拖动启动器 InteractiveObject 调度。InteractiveObject
 Inherited在将拖动对象放置到目标上且已通过对 DragManager.acceptDragDrop() 的调用接受该放置操作时,由目标 InteractiveObject 调度。InteractiveObject
 Inherited当拖动手势进入其边界时由 InteractiveObject 调度。InteractiveObject
 Inherited当拖动手势离开其边界时由 InteractiveObject 调度。InteractiveObject
 Inherited当拖动手势保持在其边界内时,由 InteractiveObject 持续调度。InteractiveObject
 Inherited在拖动操作开始时由在 DragManager.doDrag() 调用中指定为拖动启动器的 InteractiveObject 调度。InteractiveObject
 Inherited在拖动操作期间由在 DragManager.doDrag() 调用中指定为拖动启动器的 InteractiveObject 调度。InteractiveObject
 Inherited在用户为粘贴操作激活特定于平台的加速键组合或从文本上下文菜单中选择“粘贴”时调度。InteractiveObject
 Inherited当用户将活动笔针放低经过屏幕的邻近检测阈值上时调度。InteractiveObject
 Inherited
    proximityEnd
当用户将活动笔针抬高放在屏幕的邻近检测阈值上时调度。InteractiveObject
 Inherited当用户将活动笔针移动到屏幕上但仍保留在邻近检测阈值中时调度。InteractiveObject
 Inherited
    proximityOut
当用户直接将活动笔针从此 InteractiveObject 上移开但仍保留在屏幕的邻近检测阈值中时调度。InteractiveObject
 Inherited当用户直接将活动笔针移动到此 InteractiveObject 上但仍保留在屏幕的邻近检测阈值中时调度。InteractiveObject
 Inherited当用户从此 InteractiveObject 及其任一子项中移开而仍保留在屏幕的邻近检测阈值中时调度。InteractiveObject
 Inherited当用户将活动笔针从显示列表中子项的对象树中滑过此 InteractiveObject 时(而仍保留在屏幕的邻近检测阈值中)时调度。InteractiveObject
 Inherited在用户首先在 InteractiveObject 实例上按下按钮,然后将指针设备移离 InteractiveObject 实例,释放指针设备上的按钮时调度。InteractiveObject
 Inherited将要从显示列表中删除显示对象时调度。DisplayObject
 Inherited在从显示列表中直接删除显示对象或删除包含显示对象的子树时调度。DisplayObject
 Inherited[广播事件] 将要更新和呈现显示列表时调度。DisplayObject
 Inherited当用户在同一 InteractiveObject 上按下并释放用户指针设备的右按钮时调度。InteractiveObject
 Inherited当用户在 InteractiveObject 实例上按下指针设备按钮时调度。InteractiveObject
 Inherited当用户在 InteractiveObject 实例上释放指针设备按钮时调度。InteractiveObject
 Inherited用户将指针设备从 InteractiveObject 实例上移开时调度。InteractiveObject
 Inherited用户将指针设备移动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited在用户为全选操作激活特定于平台的加速键组合或从文本上下文菜单中选择“全选”时调度。InteractiveObject
 Inherited在放开软键盘之后立即调度。InteractiveObject
 Inherited在放开软键盘之前立即调度。InteractiveObject
 Inherited在隐藏软键盘之后立即调度。InteractiveObject
 Inherited对象的 tabChildren 标志值发生更改时调度。InteractiveObject
 Inherited对象的 tabEnabled 标志发生更改时调度。InteractiveObject
 Inherited对象的 tabIndex 属性值发生更改时调度。InteractiveObject
 Inherited当用户输入一个或多个文本字符时调度。InteractiveObject
 Inherited当用户第一次触摸启用触摸的设备时(例如,用手指触摸配有触摸屏的移动电话或平板)调度。InteractiveObject
 Inherited当用户移除与启用触摸的设备的接触时(例如,将手指从配有触摸屏的移动电话或平板电脑上抬起)调度。InteractiveObject
 Inherited当用户触碰设备时进行调度,而且会连续调度,直到接触点被删除。InteractiveObject
 Inherited当用户将接触点从启用触摸的设备上的 InteractiveObject 实例移开时(例如,在配有触摸屏的移动电话或平板电脑上,将手指从一个显示对象拖到另一个显示对象)调度。InteractiveObject
 Inherited当用户在启用触摸的设备的 InteractiveObject 实例上移动接触点时(例如,在配有触摸屏的移动电话或平板电脑上,将手指从显示对象外的一点拖动到显示对象上的一点)调度。InteractiveObject
 Inherited当用户移动接触点,使其远离启用触摸的设备上的 InteractiveObject 实例时(例如,在配有触摸屏的移动电话或平板电脑上将一个手指从显示对象上的一点移动到显示对象外的一点)调度。InteractiveObject
 Inherited当用户在启用触摸的设备的 InteractiveObject 实例上移动接触点时(例如,在配有触摸屏的移动电话或平板电脑上,将手指从显示对象外的一点拖动到显示对象上的一点)调度。InteractiveObject
 Inherited当用户在启用触摸设备上的已启动接触的同一 InteractiveObject 实例上抬起接触点时(例如,在配有触摸屏的移动电话或平板的显示对象上的某一点处按下并释放手指)调度。InteractiveObject
属性详细信息

content

属性
content:DisplayObject  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

包含使用 load()loadBytes() 方法加载的 SWF 文件或图像(JPG、PNG 或 GIF)文件的根显示对象。



实现
    public function get content():DisplayObject

引发
SecurityError — 加载的 SWF 文件或图像文件属于您无权访问的安全沙箱。对于加载的 SWF 文件,可以避免这种情况的方法是:使该文件调用 Security.allowDomain() 方法,或在您调用 load()loadBytes() 方法时使加载文件指定 loaderContext 参数,并将该参数的 securityDomain 属性设置为 SecurityDomain.currentDomain

相关 API 元素

contentLoaderInfo

属性 
contentLoaderInfo:LoaderInfo  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

返回与正在加载的对象相对应的 LoaderInfo 对象。LoaderInfo 对象在 Loader 对象和加载的内容对象之间共享。LoaderInfo 对象提供有关加载的文件的加载进度信息和统计。

与加载相关的事件由 Loader 对象的 contentLoaderInfo 属性引用的 LoaderInfo 对象调度。contentLoaderInfo 属性设置为有效的 LoaderInfo 对象(即使在加载内容之前),这样您就可以在加载前将事件侦听器添加到该对象。

要检测加载的 SWF 中发生的未捕获错误,请使用 Loader.uncaughtErrorEvents 属性而不是 Loader.contentLoaderInfo.uncaughtErrorEvents 属性。



实现
    public function get contentLoaderInfo():LoaderInfo

相关 API 元素


示例  ( 如何使用本示例 )
以下示例显示如何使用 Loader 对象的 contentLoaderInfo 属性上的 Loader 类和 complete 事件在 ActionScript 3.0 中加载和定位图像。ActionScriptExamples.com 提供的示例。
var url:String = "http://www.helpexamples.com/flash/images/image2.jpg";
var urlRequest:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
loader.load(urlRequest);
addChild(loader);
 
function loader_complete(evt:Event):void {
    var target_mc:Loader = evt.currentTarget.loader as Loader;
    target_mc.x = (stage.stageWidth - target_mc.width) / 2;
    target_mc.y = (stage.stageHeight - target_mc.height) / 2;
}

uncaughtErrorEvents

属性 
uncaughtErrorEvents:UncaughtErrorEvents  [只读]

语言版本: ActionScript 3.0
运行时版本: Flash Player 10.1, AIR 2

在此 Loader 对象加载的 SWF 中发生未处理错误时调度 uncaughtError 事件的对象。当任何 try..catch 块引发错误时,或调度的 ErrorEvent 对象没有注册的侦听器时,会发生未被捕获的错误。

请注意,Loader 对象的 uncaughtErrorEvents 属性调度通过该对象冒泡的事件,而不是该对象直接调度的事件。它永远不会在目标阶段调度 uncaughtErrorEvent。它仅在捕获阶段和冒泡阶段调度该事件。要检测当前 SWF(在其中定义 Loader 对象)中未被捕获的错误,请改用 LoaderInfo.uncaughtErrorEvents 属性。

如果 Loader 对象加载的内容是 AVM1 (ActionScript 2) SWF 文件,则 AVM1 SWF 文件中未被捕获的错误不会导致 uncaughtError 事件。



实现
    public function get uncaughtErrorEvents():UncaughtErrorEvents

相关 API 元素


示例  ( 如何使用本示例 )
以下示例演示了使用未被捕获的错误事件处理程序检测加载的 SWF 中的未被捕获的错误的过程。此示例定义了一个 uncaughtError 事件处理程序来检测未被捕获的错误。

在构造函数中,代码创建了一个 Loader 对象并为由 Loader 对象的 uncaughtErrorEvents 属性调度的 uncaughtError 事件注册了一个侦听器。

uncaughtErrorHandler() 方法中,代码检查 error 属性的数据类型并做出相应的响应。

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.ErrorEvent;
    import flash.events.UncaughtErrorEvent;
    import flash.net.URLRequest;

    public class LoaderUncaughtErrorEventExample extends Sprite
    {
        private var ldr:Loader;
        
        public function LoaderUncaughtErrorEventExample()
        {
            ldr = new Loader();
            ldr.load(new URLRequest("child.swf"));
            ldr.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
        }
        
        private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
        {
            if (event.error is Error)
            {
                var error:Error = event.error as Error;
                // do something with the error
            }
            else if (event.error is ErrorEvent)
            {
                var errorEvent:ErrorEvent = event.error as ErrorEvent;
                // do something with the error
            }
            else
            {
                // a non-Error, non-ErrorEvent type was thrown and uncaught
            }
        }
    }
}
构造函数详细信息

Loader

()构造函数
public function Loader()

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

创建一个可用于加载文件(如 SWF、JPEG、GIF 或 PNG 文件)的 Loader 对象。调用 load() 方法可将资源加载为 Loader 实例的子级。然后,可以将 Loader 对象添加到显示列表(例如,通过使用 DisplayObjectContainer 实例的 addChild() 方法)。这样,资源在加载时会出现在舞台上。

您也可以在“offlist”模式下使用 Loader 实例,这样就不会将 Loader 实例添加到显示列表的显示对象容器中。在该模式下,Loader 实例可以用于加载包含应用程序的其它模块的 SWF 文件。

要检测何时可以完成 SWF 文件的加载,您可以使用与 Loader 对象的 contentLoaderInfo 属性相关联的 LoaderInfo 对象的事件。此时,便可执行模块 SWF 文件中的代码以初始化和启动模块。在 offlist 模式下,还可以使用 Loader 实例来加载包含组件或媒体资源的 SWF 文件。同时,您可以使用 LoaderInfo 对象事件通知来检测组件的加载何时完成。此时,应用程序可以通过实例化代表这些组件和资源的 ActionScript 3.0 类来开始使用 SWF 文件库中的组件和媒体资源。

要确定 Loader 对象的状态,请监视与 Loader 对象的 contentLoaderInfo 属性相关联的 LoaderInfo 对象的以下事件:

  • 在加载开始时调度 open 事件。
  • 在无法加载文件或在加载过程中出现错误时,调度 ioErrorsecurityError 事件。
  • 在文件加载过程中会不断引发 progress 事件。
  • 在文件完成下载但加载的影片剪辑的方法和属性尚不可用时调度 complete 事件。
  • 在可以访问加载的 SWF 文件的属性和方法,即可以开始操作加载的 SWF 文件时调度 init 事件。在 complete 处理函数之前调度该事件。在流式 SWF 文件中,init 事件可以在明显早于 complete 事件的时间发生。在大多数情况下,请使用 init 处理函数。

注意(仅限 iOS):在 iOS 上的 AIR 应用程序中,只能从应用程序包加载包含 ActionScript 的 SWF 文件。此限制针对的是任何 ActionScript,如为 ActionScript 导出类名称的资源。若想加载 SWF 文件,加载的 SWF 必须与父 SWF 使用相同的应用程序域。

在 AIR 3.6 之前,无论是从应用程序包还是通过网络加载 SWF 文件,只能加载不包含 ActionScript 字节代码的 SWF 文件。若想使用包含 ActionScript 的外部 SWF 文件,可用一种替代方法,即创建一个 SWC 库,然后将其链接到您的主 SWF。

当应用程序运行在 iOS 模拟器中(ipa-test-interpreter-simulator 或 ipa-debug-interpreter-simulator)或解释器模式下(ipa-test-interpreter 或 ipa-debug-interpreter)时,这些限制不适用。

相关 API 元素

方法详细信息

close

()方法
public function close():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

取消当前正在对 Loader 实例执行的 load() 方法操作。

相关 API 元素

load

()方法 
public function load(request:URLRequest, context:LoaderContext = null):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将 SWF、JPEG、渐进式 JPEG、非动画 GIF 或 PNG 文件加载到此 Loader 对象的子对象中。如果加载 GIF 动画文件,将仅显示第一帧。由于 Loader 对象可以只包含一个子级,因此,发出后续 load() 请求将终止先前的请求,如果仍然存在未处理的请求,则会开始新的加载。

注意:在 AIR 1.5 和 Flash Player 10 中,所加载图像的最大宽度或高度为 8,191 像素,并且像素总数不能超过 16,777,215 像素。(因此,如果所加载图像的宽度为 8,191 像素,则其高度只能为 2,048 像素。)在 Flash Player 9 及早期版本和 AIR 1.1 及早期版本中,高度最大为 2,880 像素,宽度最大为 2,880 像素。

加载到 Loader 对象中的 SWF 文件或图像会继承该 Loader 对象的父显示对象的位置、旋转和缩放属性。

使用 unload() 方法可删除用此方法加载的影片或图像,或者取消正在进行中的加载操作。

可以在包含 SWF 内容的 HTML 页中设置 objectembed 标签的 allowNetworking 参数,防止 SWF 文件使用此方法。

iOS 注意事项

在 iOS 上的 AIR 应用程序中,只能从应用程序包加载包含 ActionScript 的 SWF 文件。此限制针对的是任何 ActionScript,如为 ActionScript 导出类名称的资源。若想加载 SWF 文件,加载的 SWF 必须与父 SWF 使用相同的应用程序域,如下例所示:

     var loader:Loader = new Loader();
     var url:URLRequest = new URLRequest("swfs/SecondarySwf.swf");
     var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
     loader.load(url, loaderContext);

此外,在 iOS 上,您不能在加载包含任何 ActionScript 字节码 (ABC) 的 SWF 文件之后卸载它然后再重新加载它。如果您试图这样做,运行时会引发错误 3764。

在 AIR 3.6 之前,无论是从应用程序包还是通过网络加载 SWF 文件,只能加载不包含 ActionScript 字节代码的 SWF 文件。若想使用包含 ActionScript 的外部 SWF 文件,可用一种替代方法,即创建一个 SWC 库,然后将其链接到您的主 SWF。

当应用程序运行在 iOS 模拟器中(ipa-test-interpreter-simulator 或 ipa-debug-interpreter-simulator)或解释器模式下(ipa-test-interpreter 或 ipa-debug-interpreter)时,这些限制不适用。

Loader 安全性

使用此方法时,请考虑 Loader 类说明中描述的 Flash Player 安全模型。

在 Flash Player 10 和更高版本中,如果使用包含上载(由 POST 体内的“content-disposition”标头中的“filename”参数表示)的 multipart Content-Type(例如“multipart/form-data”),则 POST 操作会受应用于上载的安全规则的约束:

  • 必须执行 POST 操作以响应用户启动的操作(如鼠标单击或按键)。
  • 如果 POST 操作是跨域的(POST 目标与发送 POST 请求的 SWF 文件不在同一台服务器上),则目标服务器必须提供一个允许跨域访问的 URL 策略文件。

同样,对于任何 multipart Content-Type,语法必须有效(根据 RFC2046 标准)。如果语法无效,则 POST 操作受应用于上载的安全规则约束。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性

参数

request:URLRequest — 要加载的 SWF、JPEG、GIF 或 PNG 文件的绝对或相对 URL。相对路径必须相对于主 SWF 文件。绝对 URL 必须包括协议引用,如 http:// 或 file:///。文件名不能包括磁盘驱动器指定。
 
context:LoaderContext (default = null) — LoaderContext 对象,它具有定义下列内容的属性:
  • 是否应在加载对象时检查策略文件是否存在
  • 被加载的对象的 ApplicationDomain
  • 加载的对象的 SecurityDomain
  • 加载的图像对象的 ImageDecodingPolicy

如果未指定 context 参数或者该参数引用了 null 对象,则已加载的内容将保留在自己的安全域中。

仅限 iOS:当在 AIR for iOS 中调用 load() 方法时,LoaderContext 实例必须指定主应用程序域 (ApplicationDomain.currentDomain)。

有关完整的详细信息,请参阅 LoaderContext 类中的属性说明。


事件
asyncError:AsyncErrorEvent — 如果 LoaderContext.requestedContentParent 属性已指定并且不可能将加载的内容作为子级添加到指定的 DisplayObjectContainer,则由 contentLoaderInfo 对象调度。如果加载的内容为 flash.display.AVM1Movie,或者 addChild() 调用 requestedContentParent 时引发了错误,则可能发生这种情况。
 
complete:Event — 在文件完成加载时由 contentLoaderInfo 对象调度。complete 事件始终在 init 事件之后调度。
 
httpStatus:HTTPStatusEvent — 在通过 HTTP 发出网络请求并且 Flash Player 可以检测到 HTTP 状态代码时,由 contentLoaderInfo 对象调度。
 
init:Event — 在可以访问所加载的 SWF 文件的属性和方法时,由 contentLoaderInfo 对象调度。init 事件始终在 complete 事件之前。
 
ioError:IOErrorEvent — 在发生会导致加载操作失败的输入或输出错误时,由 contentLoaderInfo 对象调度。
 
open:Event — 在加载操作开始时,由 contentLoaderInfo 对象调度。
 
progress:ProgressEvent — 在加载操作进行过程中接收到数据时,由 contentLoaderInfo 对象调度。
 
securityError:SecurityErrorEvent — 当位于只能与本地文件系统内容交互的沙箱中的 SWF 文件尝试加载只能与远程内容交互的沙箱中的内容时(反之亦然),由 contentLoaderInfo 对象调度。
 
securityError:SecurityErrorEvent — 如果 LoaderContext.requestedContentParent 属性已指定并且 LoaderContext.requestedContentParent 的安全沙箱不能访问加载的 SWF,则由 contentLoaderInfo 对象调度。
 
unload:Event — 在删除所加载的对象时,由 contentLoaderInfo 对象调度。

引发
IOError request 对象的 digest 属性不是 null。如果在加载 SWZ 文件(一个 Adobe 平台组件)时调用 URLLoader.load() 方法,仅应设置 URLRequest 对象的 digest 属性。
 
SecurityError LoaderContext.securityDomain 的值必须是 nullSecurityDomain.currentDomain。这说明您只能将被加载的媒体放置在其原始的安全沙箱或您自己的安全沙箱中(后者需要策略文件)。
 
SecurityError — 本地 SWF 文件只能将 LoaderContext.securityDomain 设置为 null。不允许将非本地媒体导入到本地沙箱中,或者将其它本地媒体放置在除其原始沙箱以外的其它位置。
 
SecurityError — 无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。
 
SecurityError — 如果 context 参数的 applicationDomainsecurityDomain 属性来自不允许的域。
 
SecurityError — 如果本地 SWF 文件尝试使用 context 参数的 securityDomain 属性。
 
IllegalOperationError — 如果 context 参数的 requestedContentParent 属性为 Loader
 
IllegalOperationError — 如果 LoaderContext.parameters 参数设置为非 null,并且具有不是字符串的某些值。
 
IllegalOperationError — 在 iOS 上,如果应用程序试图加载的 SWF 文件使用的应用程序域与主应用程序域不同。
 
IllegalOperationError — 在 iOS 上,如果应用程序试图重新加载的 SWF 曾经加载然后又卸载过且包含 ABC 码。
 
Error — 在 iOS 上,如果应用程序试图从外部应用程序包加载包含 ActionScript 代码的 SWF 文件。无法捕获此错误。应用程序屏幕上将出现一个对话框,标题为“未编译的 ActionScript”。在 AIR 3.6 之前,当试图加载的 SWF 文件包含 ActionScript 时,无论该文件是外部文件还是包括在应用程序包中,都会发生此错误。

相关 API 元素

loadBytes

()方法 
public function loadBytes(bytes:ByteArray, context:LoaderContext = null):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从 ByteArray 对象中所存储的二进制数据中加载。

loadBytes() 方法是异步的。必须等待“init”事件出现才能访问已加载对象的属性。

使用此方法时,请考虑 Loader 类说明中描述的 Flash Player 安全模型。

注意(仅限 iOS):在 iOS 上的 AIR 应用程序中,只能从应用程序包加载包含 ActionScript 的 SWF 文件。此限制针对的是任何 ActionScript,如为 ActionScript 导出类名称的资源。若想加载 SWF 文件,加载的 SWF 必须与父 SWF 使用相同的应用程序域。

在 AIR 3.6 之前,在 iOS 上调用此方法无效。

参数

bytes:ByteArray — 一个 ByteArray 对象。ByteArray 的内容可以采用受 Loader 类支持的任何文件格式:SWF、GIF、JPEG 或 PNG。
 
context:LoaderContext (default = null) — 一个 LoaderContext 对象。只应用 LoaderContext 对象的 applicationDomain 属性;不应用 LoaderContext 对象的 checkPolicyFilesecurityDomain 属性。

如果未指定 context 参数或者该参数引用了 null 对象,则内容将加载到当前的安全域(在 Flash Player 安全文档中称为“导入加载”的进程)中。具体来说,如果执行加载的 SWF 文件通过将远程 SWF 并入到其代码中来信任远程 SWF,则执行加载的 SWF 可直接将其导入到自己的安全域中。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性


事件
asyncError:AsyncErrorEvent — 如果 LoaderContext.requestedContentParent 属性已指定并且不可能将加载的内容作为子级添加到指定的 DisplayObjectContainer,则由 contentLoaderInfo 对象调度。如果加载的内容为 flash.display.AVM1Movie,或者 addChild() 调用 requestedContentParent 时引发了错误,则可能发生这种情况。
 
complete:Event — 当操作完成时由 contentLoaderInfo 对象调度。complete 事件始终在 init 事件之后调度。
 
init:Event — 当已加载数据的属性和方法可以访问时由 contentLoaderInfo 对象调度。init 事件始终在 complete 事件之前。
 
ioError:IOErrorEvent — 当运行时无法分析字节数组中的数据时由 contentLoaderInfo 对象调度。
 
open:Event — 当操作开始时由 contentLoaderInfo 对象调度。
 
progress:ProgressEvent — 当数据传输至内存时由 contentLoaderInfo 对象调度。
 
securityError:SecurityErrorEvent — 如果 LoaderContext.requestedContentParent 属性已指定并且 LoaderContext.requestedContentParent 的安全沙箱不能访问加载的 SWF,则由 contentLoaderInfo 对象调度。
 
unload:Event — 在删除所加载的对象时,由 contentLoaderInfo 对象调度。

引发
ArgumentError — 如果 ByteArray 对象的 length 属性不大于 0。
 
IllegalOperationError — 如果 context 参数的 checkPolicyFilesecurityDomain 属性为非空。
 
IllegalOperationError — 如果 context 参数的 requestedContentParent 属性为 Loader
 
IllegalOperationError — 如果 LoaderContext.parameters 参数设置为非 null,并且具有不是字符串的某些值。
 
IllegalOperationError — 在 iOS 上,如果应用程序试图加载的 SWF 文件使用的应用程序域与主应用程序域不同。
 
IllegalOperationError — 在 iOS 上,如果应用程序试图重新加载的 SWF 曾经加载然后又卸载过且包含 ABC 码。
 
Error — 在 iOS 上,如果应用程序试图从外部应用程序包加载包含 ActionScript 代码的 SWF 文件。无法捕获此错误。应用程序屏幕上将出现一个对话框,显示消息“未编译的 ActionScript”。在 AIR 3.6 之前,当试图加载的 SWF 文件包含 ActionScript 时,无论该文件是外部文件还是包括在应用程序包中,都会发生此错误。
 
SecurityError — 如果提供的 context 属性的 applicationDomain 属性来自不允许的域。
 
SecurityError — 无法连接到常用的保留端口。有关已阻止的端口的完整列表,请参阅《ActionScript 3.0 开发人员指南》中的“限制网络 API”。

相关 API 元素

    loadFilePromise

()方法 
public function loadFilePromise(promise:IFilePromise, context:LoaderContext = null):void

语言版本: ActionScript 3.0
运行时版本: AIR 2.5

加载 IFilePromise 实例。

loadFilePromise 方法使用 IFilePromise 对象并加载二进制数据。如果数据是渐进流,例如视频,则在访问加载的对象的属性之前等待“init”或 progress 事件。否则,等待 complete 事件以确保完全加载了数据。

使用此方法时,请考虑 Loader 类说明中描述的 Flash Player 安全模型。

参数

promise:IFilePromise — IFilePromise 对象。对象的数据源可以采用 Loader 类支持的任何文件格式:SWF、GIF、JPEG 或 PNG。
 
context:LoaderContext (default = null) — 一个 LoaderContext 对象。只应用 LoaderContext 对象的 applicationDomain 属性;不应用 LoaderContext 对象的 checkPolicyFilesecurityDomain 属性。

如果未指定 context 参数或者该参数引用了 null 对象,则内容将加载到当前的安全域(在 Flash Player 安全文档中称为“导入加载”的进程)中。具体来说,如果执行加载的 SWF 文件通过将远程 SWF 并入到其代码中来信任远程 SWF,则执行加载的 SWF 可直接将其导入到自己的安全域中。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性


事件
asyncError:AsyncErrorEvent — 如果 LoaderContext.requestedContentParent 属性已指定并且不可能将加载的内容作为子级添加到指定的 DisplayObjectContainer,则由 contentLoaderInfo 对象调度。如果加载的内容为 flash.display.AVM1Movie,或者 addChild() 调用 requestedContentParent 时引发了错误,则可能发生这种情况。
 
complete:Event — 当操作完成时由 contentLoaderInfo 对象调度。complete 事件始终在 init 事件之后调度。
 
init:Event — 当已加载数据的属性和方法可以访问时由 contentLoaderInfo 对象调度。init 事件始终在 complete 事件之前。
 
ioError:IOErrorEvent — 如果运行时无法分析数据源中的数据或数据源流不可读,则由 contentLoaderInfo 对象调度。
 
open:Event — 当操作开始时由 contentLoaderInfo 对象调度。
 
progress:ProgressEvent — 当数据传输至内存时由 contentLoaderInfo 对象调度。
 
securityError:SecurityErrorEvent — 如果 LoaderContext.requestedContentParent 属性已指定并且 LoaderContext.requestedContentParent 的安全沙箱不能访问加载的 SWF,则由 contentLoaderInfo 对象调度。
 
unload:Event — 在删除所加载的对象时,由 contentLoaderInfo 对象调度。

引发
IllegalOperationError — 如果 context 参数的 requestedContentParent 属性为 Loader
 
IllegalOperationError — 如果 LoaderContext.parameters 参数设置为非 null,并且具有不是字符串的某些值。
 
ArgumentError — 如果作为参数传递的 IFilePromise 对象为 null。

相关 API 元素

unload

()方法 
public function unload():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

删除此 Loader 对象中使用 load() 方法加载的子项。将关联 LoaderInfo 对象的 property 重置为 null。不必破坏子级,因为其它对象可能要引用它;但是,它不再是 Loader 对象的子级。

调用 unload() 方法时,应将 Loader 对象的 contentLoaderInfo 属性设为 null。曾经与 SWF 一起加载的任何可视资源都将予以卸载,并从内存中删除。加载的 SWF 中的 ActionScript 类定义保留在内存中,与加载的 SWF 处于同一应用程序域中的代码可以访问这些类的实例并创建新的实例。

注意(仅限 iOS):在 AIR 3.6 之前,此方法在 iOS 上无效。

最佳做法是,在卸载子 SWF 文件之前,您应该明确关闭子 SWF 文件的对象(如 LocalConnection、NetConnection、NetStream 和 Sound 对象)中的任何流。否则,子 SWF 文件中的音频可能会继续播放,即使已卸载子级 SWF 文件。要关闭子 SWF 文件中的流,请向子文件中添加事件侦听器以侦听 unload 事件。当父文件调用 Loader.unload() 时,将为子文件调度 unload 事件。以下代码显示了完成上述任务的方法:

function closeAllStreams(evt:Event) { 
    myNetStream.close();
    mySound.close();
    myNetConnection.close();
    myLocalConnection.close();
}

myMovieClip.loaderInfo.addEventListener(Event.UNLOAD, closeAllStreams);

相关 API 元素

unloadAndStop

()方法 
public function unloadAndStop(gc:Boolean = true):void

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5, Flash Lite 4

尝试卸载子 SWF 文件内容并停止执行已加载的 SWF 文件中的命令。此方法尝试通过删除对子 SWF 文件的 EventDispatcher、NetConnection、Timer、Sound 或 Video 对象的引用,从而卸载使用 Loader.load()Loader.loadBytes() 加载的 SWF 文件。因此,针对子 SWF 文件和子 SWF 文件的显示列表将发生以下行为:

  • 停止声音。
  • 删除舞台事件侦听器。
  • 删除 enterFrameframeConstructedexitFrameactivatedeactivate 的事件侦听器。
  • 停止计时器。
  • 断开摄像头和麦克风实例
  • 停止影片剪辑。

调用 unloadAndStop() 方法时,应将 Loader 对象的 contentLoaderInfo 属性设为 null。曾经与 SWF 一起加载的任何可视资源都将予以卸载,并从内存中删除。加载的 SWF 中的 ActionScript 类定义保留在内存中,与加载的 SWF 处于同一应用程序域中的代码可以访问这些类的实例并创建新的实例。

注意(仅限 iOS):在 AIR 3.6 之前,此方法在 iOS 上无效。

参数

gc:Boolean (default = true) — 提示垃圾回收器对 SWF 子对象执行 (true) 还是不执行 (false) 垃圾回收。如果要以异步方式卸载很多对象,则将 gc 参数设置为 false 可能会提高应用程序的性能。但是,如果将该参数设置为 false,则在运行 unloadAndStop() 命令之后,子 SWF 文件的媒体和显示对象可能还会保存在内存中。

相关 API 元素

LoaderExample.as

下例用 LoaderExample 类来说明如何使用各种事件侦听器。执行下列步骤可完成该任务:
  1. 创建 url 属性,它是图像文件的位置和名称
  2. LoaderExample 构造函数中,创建一个新的 Loader 对象,名为 loader,该对象随后被传递给 configureListeners() 方法,如步骤 3 所述。
  3. 构造函数创建一个 URLRequest 对象的新实例 request,该实例带有传递的 url,这样,就可以知道文件的名称和位置。
  4. request 对象传递给 loader 对象的 load() 方法,该方法会将图像加载到显示列表上。
  5. 为加载器上的 click 事件注册 clickHandler 事件侦听器。在单击鼠标后,便可卸载加载的图像。
  6. configureListeners() 方法通过以下方法添加 7 个事件侦听器:
    • 图像加载完成时,执行 completeHandler() 方法。
    • 图像不是在本地加载,并且只有在网络请求可用并可被 Flash Player 检测到的情况下,才会执行 httpStatusHandler() 方法。
    • initHandler() 方法在 completeHandler() 方法之前、progressHandler() 方法之后执行。通常,init 事件在加载 SWF 文件时更有用。
    • 图像文件不可用或不可访问,则执行 ioErrorHandler() 方法。
    • 首次打开图像文件时,执行 openHandler() 方法。
    • 图像文件开始下载和下载完成时,执行 progressHandler() 方法。
    • 通过使用用户单击图像时使用的 unload() 方法卸载图像时,执行 unLoadHandler() 方法。

请牢记以下要求:

  • 该示例要求您将名为 Image.gif 的文件放置在与经过编译的 SWF 文件相同的目录中。使用具有一个适合主 SWF 文件尺寸的区域的图像。
  • 虽然该示例使用可用于 LoaderInfo 对象的所有事件,但是在大部分情况下,只需要一个子集。特别是在只加载图像文件时,complete 事件(还可能是 ioError 事件)足够用于加载本地图像。
package {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLRequest;

    public class LoaderExample extends Sprite {
        private var url:String = "Image.gif";

        public function LoaderExample() {
            var loader:Loader = new Loader();
            configureListeners(loader.contentLoaderInfo);
            loader.addEventListener(MouseEvent.CLICK, clickHandler);

            var request:URLRequest = new URLRequest(url);
            loader.load(request);

            addChild(loader);
        }

        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(Event.INIT, initHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }

        private function initHandler(event:Event):void {
            trace("initHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }

        private function unLoadHandler(event:Event):void {
            trace("unLoadHandler: " + event);
        }

        private function clickHandler(event:MouseEvent):void {
            trace("clickHandler: " + event);
            var loader:Loader = Loader(event.target);
            loader.unload();
        }
    }
}




[ X ]为什么显示为英语?
《ActionScript 3.0 参考》中的内容以英语显示

《ActionScript 3.0 参考》中的部分内容未翻译成所有语言。当某个语言元素未翻译时,将显示为英语。例如,ga.controls.HelpBox 类未翻译成任何语言。因此在简体中文版的参考中,ga.controls.HelpBox 类显示为英语。