zoukankan      html  css  js  c++  java
  • AS3加载图片的2种方法

    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);
            }
            //事件,下载完毕
            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);
            }
            //事件,下载中
            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 = '已经下载'+m_percent.toString()+'%';
            }
        }
     
    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);
            }
            //事件,装载完毕
            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);
            }
        }
    }
  • 相关阅读:
    10.19NOIP模拟赛(DAY2)
    bzoj1880: [Sdoi2009]Elaxia的路线(spfa,拓扑排序最长路)
    P3469 [POI2008]BLO-Blockade(Tarjan 割点)
    P2746 [USACO5.3]校园网Network of Schools(Tarjan)
    10.17NOIP模拟赛
    10.16NOIP模拟赛
    P3953 逛公园(dp,最短路)
    牛客OI周赛2-提高组
    洛谷 P1948 [USACO08JAN]电话线Telephone Lines 题解
    洛谷 P2563 [AHOI2001]质数和分解 题解
  • 原文地址:https://www.cnblogs.com/mzbdadou/p/2409905.html
Copyright © 2011-2022 走看看