Using the flash.display.Loader
class in AS3, you can load in external image files to display in flash.
The loader class supports loading in JPG, SWF, PNG, or GIF file types.
The Loader class sounds more like a loading manager that watches load
progress, rather than a display object. Fact is, the Loader is treated
as a DisplayObject
,
so when it’s ready you just add it to the stage. Pretty simple, so
let’s get started!
First, you will need to create an instance of the loader class and
add a couple event listeners to it. One to watch load progress, and one
to watch for when the loading is complete.
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
You’ll notice that I’m not adding the event listener to the loader
instance (myLoader), but instead adding them to a property of myLoader
called contentLoaderInfo
.
The Loader class has a special property that controls all the
loading events. This property is an instance of the LoaderInfo
class, so we will listen to it for events, rather than our Loader
instance.
Next, we will call the Loader.load()
method to initiate the loading sequence. You will need to create a new
variable that will be an instance of the URLRequest
class. This new variable will be passed to the load() method.
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest("myImage.jpg");
myLoader.load(fileRequest);
Ok, so that’s pretty much it. All that is left is to create our callback
methods for each of our eventListeners. Our final code should look like
this:
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest("myImage.jpg");
myLoader.load(fileRequest);
public function onProgressStatus(e:ProgressEvent) {
// this is where progress will be monitored
trace(e.bytesLoaded, e.bytesTotal);
}
public function onLoaderReady(e:Event) {
// the image is now loaded, so let's add it to the display tree!
addChild(myLoader);
}
详细请看
http://www.republicofcode.com/tutorials/flash/as3loader/
分享到:
相关推荐
第1篇 ActionScript3.0语言基础 第1章 ActionScript3.0概述 第2章 搭建ActionScript3.0开发环境 第3章 ActionScript3.0语法 第2篇 ActionScript3.0面向对象特性 第4章 ActionScript3.0面向对象编程 第...
actionscript3.0开发的进度显示条项目
《ActionScript 3.0 语言和组件参考》概述 《ActionScript 3.0 语言参考》是 Flash® Player 和 Adobe AIR™ 应用程序编程接口 (API) 的参考手册。 此版本包括支持 Adobe AIR 运行时环境的新 ActionScript 类、...
最专业的最专业的最专业的ActionScript 3.0 ActionScript 3.0 ActionScript 3.0 ActionScript 3.0 ActionScript 3.0
本书详细地介绍了 actionscript 3.0的基础知识,包括 actionscript 3.0语言、actionscript 3.0对象的操作方法、显示列表的使用、事件模型、加载外部素材、可视化编程以及利用声音和视频增强应用程序等方面的知识,并...
本书全面介绍了ActionScript 3.0的基本语法、类的架构以及面向对象程序的设计理念。内容安排上既适合刚刚接触到ActionScript脚本语言的初学者,也照顾到学习过ActionScript之前版本有一定编程经验的读者。 鉴于...
ActionScript3.0 中文版 ActionScript3.0 api 中文版说明文档
ActionScript 是针对 Adobe Flash Player 运行时环境的编程语言,它在 Flash 内容和应用 程序中实现了交互性、数据处理以及其它许多功能。 ActionScript 是由 Flash Player 中的 ActionScript 虚拟机 (AVM) 来执行的...
ActionScript3.0完全自学手册电子教案
Foundation ActionScript 3.0 Animation Making Things Move ActionScript 3.0
ActionScript 3.0 语言和组件参考概述Adobe Flex 2 语言参考ActionScript 3.0 语言和组件参考是适用于 Flash® Player 应用程序编程接口 (API) 的参考手册。 Adobe Flex 2 语言参考ActionScript 3.0 语言和组件...
用ActionScript 3.0动态绘制正弦曲线,附带源文件(包括一个.fla文件、一个.as文件、一个.swf文件)
《ActionScript 3.0 语言和组件参考》概述《ActionScript 3.0 语言参考》是 Flash® Player 和 Adobe AIR™ 应用程序编程接口 (API) 的参考手册。 此版本包括支持 Adobe AIR 运行时环境的新 ActionScript 类、方法...
ActionScript3.0cookbook中文版 ActionScript3.0cookbook中文版 ActionScript3.0cookbook中文版
《ActionScript 3.0 语言和组件参考》中文版概述 下面的《ActionScript 3.0 语言和组件参考》是 Flash® Player 应用程序编程接口 (API) 的参考手册。 下面的《ActionScript 3.0 语言和组件参考》提供 ActionScript...
actionscript 3.0 下雨actionscript 3.0 下雨actionscript 3.0 下雨actionscript 3.0 下雨actionscript 3.0 下雨
ActionScript 3.0 编程 学习FLASH BUILDER RIA 必不可少
ActionScript 3.0 开发人员指南