zoukankan      html  css  js  c++  java
  • ActionScript 多图加载 按图顺序索引

    Tag:ActionScript 加载图片 位置 顺序 多张图

    1,写一个自己的EVENT类:DataEvent

    package util
    {
        import flash.events.Event;

        public class DataEvent extends Event
        {
            public var data:String;
            public var content:Object;
            public static const COMPLETE:String="ObjectLoadOver";
            public function DataEvent(type:String=DataEvent.COMPLETE, bubbles:Boolean=false, cancelable:Boolean=false)
            {
                super(type, bubbles, cancelable);
            }
        }
    }

    2,写自己的一个Loader类:ObjectLoader

    package util{
        import flash.display.Loader;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        public class ObjectLoader extends Sprite {
            private var data:String;
            private var ld:Loader;
            public var loaded:Function;
            public function ObjectLoader(url:String,addedData:String,loadExec:Function) {
                ld=new Loader;
                ld.contentLoaderInfo.addEventListener(Event.COMPLETE,onObjectLoaded);
                ld.load(new URLRequest(url));
                loaded=loadExec;
                data=addedData;
                addEventListener(DataEvent.COMPLETE,loaded);
            }
            private function onObjectLoaded(e:Event):void {
                var event:DataEvent=new DataEvent();
                event.data=data;
                event.content=e.target.content;
                trace(e.target.content);
                //event.target.content=e.target.content;
                if (loaded!=null) {
                    dispatchEvent(event);
                } else {
                    trace("请给ObjectLoader的loaded方法赋值");
                }
            }

        }
    }

    3,调用自己的Loader

    public function Abcde()
            {
                cards=new Array(13);
                for(var i:uint=0;i<13;i++)
                {
                    var url:String="images/poke/C/"+(i+3)+".jpg";
                    var ol:ObjectLoader=new ObjectLoader(url,(i+3).toString(),LoadDone);
                }
            }
            public function LoadDone(e:DataEvent):void
            {
                trace(e.data);
                var bitmap:Bitmap=e.content as Bitmap;
                bitmap.y=top;
                bitmap.x=parseInt(e.data)*20+left;
                cards[parseInt(e.data)-3]=bitmap;
                total++;
                if(total==13)
                {
                    for(var i:uint=0;i<13;i++)
                        addChild(cards[i]);
                    }
                       }

    实现了异步加载图片,加载完成后获取图片指针

  • 相关阅读:
    html中#include file的使用方法
    【leetcode】Next Permutation
    diameter
    android listview综合使用演示样例_结合数据库操作和listitem单击长按等事件处理
    【剑指offer】链表倒数第k个节点
    【经典面试题】实现平方根函数sqrt
    对CAB文件进行数字签名
    实习面试总结
    从队列、二叉树到优先队列
    句子的理解
  • 原文地址:https://www.cnblogs.com/yangyh/p/1574302.html
Copyright © 2011-2022 走看看