ActionScript 3.0做Loader似乎有点麻烦,但肯定比ActionScript 2.0更强大。下面这个实例在用百分比显示进度的基础上,使用BitmapData类结合Timer类实现图片像素溶解出场,并为图片添加dropShadow和Bevel滤镜。当图片像素溶解到一半的时候,将移除下载状态的提示信息文本。代码如下:
package com.riafan.tutorials { import flash.text.*; import flash.display.*; import flash.events.*; import flash.filters.*; import flash.net.URLRequest; import flash.utils.Timer; import flash.geom.*; public class LoaingDemo extends MovieClip { private var bitmapData:BitmapData=new BitmapData(600,450,true,0xFFFFFFFF); private var sourceBitmapData:BitmapData=new BitmapData(600,450,true,0xFFFFFFFF); private var loader:Loader=new Loader(); private var tf:TextField; private var rec:Rectangle=sourceBitmapData.rect; private var randomSeed:uint=0; private var times:uint=30; private var numberOfPixels:uint=(rec.width*rec.height)/times; public function LoaingDemo() { //滤镜应用 var dropShadowFilter:DropShadowFilter=new DropShadowFilter(); var bevelFilter:BevelFilter=new BevelFilter(); loader.filters=[dropShadowFilter,bevelFilter]; //指定bitmap images var bitmap:Bitmap=new Bitmap(bitmapData); addChild(bitmap); //添加TextField tf=new TextField(); addChild(tf); //初始化TextField tf.text="开始下载"; tf.selectable=false; tf.autoSize = TextFieldAutoSize.CENTER; tf.background=true; tf.backgroundColor=0xFFFFCC; tf.textColor=0x000000; tf.x=(550-tf.width)/2; tf.y=(400-tf.height)/2; //下载图片 var req:URLRequest=new URLRequest(); req.url="flower.jpg"; loader.load(req); //为LoaderInfo对象注册侦听器 loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete); loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgress); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError); } //正在下载时执行 private function onProgress(e:Event):void { var info:LoaderInfo=e.target as LoaderInfo; var percent:int=((info.bytesLoaded)/(info.bytesTotal))*100; tf.text="已经下载"+percent.toString() + "%"; tf.textColor=0x009900; } //下载完毕后执行 private function onComplete(e:Event):void { var matrix:Matrix=new Matrix(.5,0,0,.5,19,8); sourceBitmapData.draw(loader,matrix); //stage应用 loader.x=(stage.stageWidth-loader.width)/2; loader.y=(stage.stageHeight-loader.height)/2; tf.text="下载完毕"; tf.textColor=0x000000; //timer应用 var timer:Timer=new Timer(60,times); var removeTimer:Timer=new Timer(1000); //注册time侦听器 timer.addEventListener(TimerEvent.TIMER,onTimer); timer.start(); } //下载出错时执行 private function onError(err:IOErrorEvent):void { tf.text=err.text; tf.textColor=0x990000; } //当Timer对象达到指定的延迟间隔时执行 private function onTimer(e:TimerEvent):void { //像素溶解特效 randomSeed=bitmapData.pixelDissolve(sourceBitmapData,rec,new Point(0,0),randomSeed,numberOfPixels); //当图片像素溶解到一半的时候,移除下载状态的提示信息文本 if (e.target.currentCount==times/2) { removeChild(tf); } } } }
说明:
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |