zoukankan      html  css  js  c++  java
  • Flash/Flex学习笔记(16):如何做自定义Loading加载其它swf

    01
    const FILE_PATH:String="main.swf";

    02
    const CLASS_NAME:String="MainSwf";

    03

    04
    var loader:Loader;

    05
    var request:URLRequest;

    06

    07
    loader = new Loader();

    08
    request=new URLRequest(FILE_PATH);

    09
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);

    10
    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgress);

    11
    loader.load(request);

    12

    13
    function onComplete(e:Event):void

    14
    var domain:ApplicationDomain=e.target.applicationDomain as ApplicationDomain;

    15
    var swfClass:Class=domain.getDefinition(CLASS_NAME) as Class;

    16
    var swfInstance:Sprite = (new swfClass()) as Sprite;

    17
    swfInstance.x=0;

    18
    swfInstance.y=0;

    19

    20
    //卸掉舞台上现有的东西    

    21
    var _childCount = numChildren;

    22
    for (var i:int=_childCount-1; i>=0; i--) {       

    23
    this.removeChildAt(i);  

    24
    }   

    25

    26
    //加载刚下载的动画

    27
    this.addChild(swfInstance);

    28
    }

    29

    30
    function onProgress(e:ProgressEvent) {

    31
    //trace(e);

    32
    label1.text = "正在加载," + e.bytesLoaded + " / " + e.bytesTotal + ", " + (Math.round(  (100 * e.bytesLoaded / e.bytesTotal) / 0.01) * 0.01) + " %";

    33
    }

    34

    35
    stop();

    解释:as3中每个fla都可以对应一个.as文件,用于实现代码界面分离,上面代码中的CLASS_NAME即为.as文件中定义的类名

    注意:如果在Main.fla中用到了系统组件(比如TileList之类),最好在Loading.fla中也拖一个出来到舞台上,然后删除,否则在loading中加载main的实例时,会出一些莫名其妙的问题!

  • 相关阅读:
    web控件文本框不响应回车事件
    封装的概念
    js 中eval的使用
    C#调用存储过程
    javascript和C#对URI编码
    比较好的博客日历控件
    扩展方法实例
    C# 集合类
    数据访问层的几种数据库连接方式
    aspnetpage分页控件的使用
  • 原文地址:https://www.cnblogs.com/happysky97/p/1884502.html
Copyright © 2011-2022 走看看