zoukankan      html  css  js  c++  java
  • flash AS +xml 加载图片(使用MovieClipLoader实现LOADING)

    该flash一共有两层,一层的第一帧用来添加要使用的按钮(btnPlay,btnBack)和动态文本框(其变量为ratio,note);二层的第一帧用来添加AS(如下所示):
    stop();
    //舞台设置为450*300;配置文件为configuration1.xml;
    var doc = new XML();
    sWidth = 450;
    sHeight = 300;
    doc.ignoreWhite = true;
    myXML = null;
    rootNode = null;
    nodeNum = 0;
    path = \"configuration1.xml\";
    stopFlag = false;
    overNum = 0;
    totalWidth = 0;
    posStr = \"\";
    ratio = 0;
    note = \"\";
    tp = 1;
    this.onLoad = function() {
    doc.load(path);//加载xml文件。
    };
    doc.onLoad = function(success) {
    if (success) {
    myXML = doc.firstChild;
    rootNode = myXML.firstChild;
    node = rootNode;
    k = 1;
    while (node.nextSibling) {
    _root[\"myload\"+k] = new MovieClipLoader();
    _root[\"myListener\"+k] = new Object();
    _root[\"myListener\"+k].onLoadStart = function(target_mc) {//加载开始时发生该事件
    //trace(\"start \"+target_mc._parent._name);
    };
    _root[\"myListener\"+k].onLoadProgress = function(target_mc, loadedBytes, totalBytes) {//在onLoadStart和onLoadComplete之间的下载过程,要show loading效果的话,就要使用该事件。如果下载速度很快的话是看不到过程的哦。
    _root.ratio = Math.round(loadedBytes/totalBytes*100);
    _root.note = \"loading \"+target_mc._parent._name.substr(3, 1)+\"th pic\";
    };
    _root[\"myListener\"+k].onLoadInit = function(target_mc) {//MOVIECLIP被加载完毕后播放第一帧的时候发生该事件。
    var tmpK = Number(target_mc._parent._name.substr(3, 1));
    target_mc._parent._x = 30;
    target_mc._parent._y = 30;
    target_mc._parent._alpha = 0;
    _root[\"pW\"+tmpK] = target_mc._width;
    _root[\"pH\"+tmpK] = target_mc._height;
    target_mc._parent._width = 450/_root[\"pH\"+tmpK]*300;
    target_mc._parent._height = 200;
    };
    _root[\"myListener\"+k].onLoadError = function(target_mc, errorcode) {//加载过程发生错误时发生该事件
    //trace(\"error\"+errorcode);
    _root.note = target_mc._parent._name.substr(3, 1)+\"cann\'t be loaded!\";
    };
    _root[\"myListener\"+k].onLoadComplete = function(target_mc) {//加载过程完毕发生该事件。
    var tmp = Number(target_mc._parent._name.substr(3, 1))+1;
    _root.note = (tmp-1)+\"th pic \"+\"loaded!\";
    _root[\"myload\"+tmp].loadClip(_root[\"urlForPic\"+tmp], _root[\"pic\"+tmp].picChild);
    };
    _root[\"myload\"+k].addListener(_root[\"myListener\"+k]);
    _root.createEmptyMovieClip(\"pic\"+k, k*10);
    _root[\"pic\"+k].createEmptyMovieClip(\"picChild\", k*100);//为什么要再创建一个空的movieclip呢,是因为只能使用被加载的movieclip(_root[\"pic\"+k].picChild)的_parent(_root[\"pic\"+k])才能控制被加载的图片或swf的属性,如width和height,
    _root[\"pic\"+k].picChild._x = 0;
    _root[\"pic\"+k].picChild._y = 0;
    _root[\"pic\"+k].onRollOver = function() {
    _root.overNum = Number(this._name.substr(3, 1));
    _root.stopFlag = true;
    };
    _root[\"pic\"+k].onEnterFrame = function() {
    if (tp == Number(this._name.substr(3, 1)) && this._alpha<100) {
    //if(tp==1)trace(this._alpha);
    this._alpha = int(this._alpha+2);
    } else if (this._alpha>0) {
    this._alpha = int(this._alpha-2);
    }
    };
    _root[\"pic\"+k].onRollOut = function() {
    _root.stopFlag = false;
    overNum = 0;
    };
    _root[\"pic\"+k].onRelease = function() {
    getURL(_root[\"str\"+this._name.substr(3, 1)]);
    };
    _root[\"str\"+k] = node.nextSibling.attributes.url;
    _root[\"txt\"+k] = node.nextSibling.attributes.des;
    _root[\"urlForPic\"+k] = node.nextSibling.attributes.pic;
    node = node.nextSibling;
    k++;
    }
    } else {
    trace(\"There was an error parsing the XML data\");
    }
    nodeNum = k-1;
    _root[\"myload\"+1].loadClip(_root[\"urlForPic\"+1], _root[\"pic\"+1].picChild);
    };
    _root.btnPlay.onRelease = function() {
    tp++;
    if (tp>nodeNum) {
    tp = 1;
    }
    };
    _root.btnBack.onRelease = function() {
    tp--;
    if (tp<=0) {
    tp = nodeNum;
    }
    };



    configuration1.xml的结构(贴出原码会被浏览器给解析并显示出来):

    confiugration
                     entry
                             des
                             url //点击图片要转到的地址。
                             pic //所加载图片的地址
  • 相关阅读:
    嵌入式成长轨迹5 【嵌入式环境及基础】【嵌入式Linux软件开发入门】【变量和运算符】
    嵌入式成长轨迹3 【嵌入式环境及基础】【嵌入式Linux软件开发入门】【VI编辑器的使用】
    嵌入式成长轨迹8 【嵌入式环境及基础】【Linux shell强化】【文本过滤】
    嵌入式成长轨迹7 【(转)十年后嵌入式设计技术将不再是独立的技术门类】
    浏览器加载和渲染html的顺序
    IE9/火狐4.0/Chrome 10 三足鼎立的浏览器之争
    为什么要叫我“美工”?
    可用性测试启发式评估十条原则介绍
    为何用户体验无法被设计,如何为用户体验设计
    浅谈web标准、可用性、可访问性
  • 原文地址:https://www.cnblogs.com/daxia/p/950878.html
Copyright © 2011-2022 走看看