[AS3]AS3如何加载jpg,png,gif图片的方法附完整示例
[AS3]AS3如何加载jpg,png,gif图片的方法附完整示例
AS3加载jpg,png,gif图片的方法示例1
- package net.burchin.loading {
- import flash.display.Sprite;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.text.TextField;
- import flash.net.URLRequest;
- import flash.events.Event;
- import flash.events.ProgressEvent;
- import flash.geom.Matrix;
- public class LoadingDoc extends Sprite {
- private var _imageData:BitmapData; //图片
- private var _loader:Loader; //装载
- private var _rate:TextField; //进度显示
- public function LoadingDoc() {
- init();
- _rate.text = '开始下载';
- _rate.autoSize = 'center';
- _rate.textColor = 0x000000;
- _rate.x = (stage.stageWidth - _rate.width)/2;
- _rate.y = (stage.stageHeight - _rate.height)/2;
- this.addChild(_rate);
- sendRequest('images/flower.jpg');
- }
- //初始化
- private function init() {
- _imageData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xFFFFFFFF);
- _loader = new Loader();
- _rate = new TextField();
- }
- //发送请求
- private function sendRequest(p_url:String) {
- var m_request = new URLRequest(p_url);
- _loader.load(m_request);
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
- _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
- }
- //Cuplayer.com事件,下载完毕
- private function onComplete(e:Event) {
- _imageData.draw(_loader, new Matrix(stage.stageWidth/_loader.width, 0, 0, stage.stageHeight/_loader.height, 0, 0));
- var m_image:Bitmap = new Bitmap(_imageData);
- this.removeChild(_rate);
- this.addChild(m_image);
- }
- //Cuplayer.com事件,下载中
- private function onProgress(e:Event) {
- var m_info:LoaderInfo = e.target as LoaderInfo;
- var m_percent:uint = (m_info.bytesLoaded/m_info.bytesTotal)*100;
- _rate.text = 'Cuplayer.com已经下载'+m_percent.toString()+'%';
- }
- }
- }
AS3加载jpg,png,gif图片的方法示例2
- package net.burchin.loading {
- import flash.display.Sprite;
- import flash.display.BitmapData;
- import flash.display.Bitmap;
- import flash.display.Loader;
- import flash.net.URLRequest;
- import flash.net.URLLoader;
- import flash.net.URLLoaderDataFormat;
- import flash.utils.ByteArray;
- import flash.events.Event;
- import flash.geom.Matrix;
- public class LoadingByByteArrayDoc extends Sprite {
- private var _imageData:BitmapData; //图片数据
- private var _loader:Loader; //装载
- public function LoadingByByteArrayDoc():void {
- init();
- sendRequest('images/flower.jpg');
- }
- //初始化
- private function init():void {
- _imageData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xFFFFFFFF);
- _loader = new Loader();
- }
- //发送请求
- private function sendRequest(p_url:String):void {
- var m_request:URLRequest = new URLRequest(p_url);
- var m_loader:URLLoader = new URLLoader();
- m_loader.dataFormat = URLLoaderDataFormat.BINARY;
- m_loader.addEventListener(Event.COMPLETE, onSendComplete);
- m_loader.load(m_request);
- }
- //事件,请求发送完毕
- private function onSendComplete(e:Event):void {
- var m_content:ByteArray = e.target.data as ByteArray;
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
- _loader.loadBytes(m_content);
- }
- //Cuplayer.com事件,装载完毕
- private function onLoadComplete(e:Event):void {
- _imageData.draw(_loader, new Matrix(stage.stageWidth/_loader.width, 0, 0, stage.stageHeight/_loader.height, 0, 0));
- var m_image:Bitmap = new Bitmap(_imageData);
- this.addChild(m_image);
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...