相册源代码

为了降低任务的难度,公布核心部分的源代码。 

stop();

import mx.transitions.Tween;
import mx.transitions.easing.*;

var RandomNumberArray:Array = new Array(“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “A”, “B”, “C”, “D”, “E”, “F”);
var BackColor:String = new String();
for (var i = 0; i<=5; i++) {
    var RandomNumber:Number = Math.floor(Math.random()*16);
    BackColor += RandomNumberArray[RandomNumber];
    ColorCode.text = “#”+BackColor;
    trace(BackColor);
}

this.createEmptyMovieClip(“BackColorSquare”,-16384);
with (BackColorSquare) {
    moveTo(0,0);
    beginFill(“0x”+BackColor,100);
    lineTo(800,0);
    lineTo(800,500);
    lineTo(0,500);
    lineTo(0,0);
    endFill();
}

var PicListXML = new XML();
var piclist:Array = new Array();
PicListXML.ignoreWhite = true;
PicListXML.onLoad = function() {
    switchPicture();
    startPreload(piclist[0]);
    trace(piclist);
};
PicListXML.load(“PictureList.xml”);

function switchPicture() {
    var PicImage = PicListXML.firstChild.childNodes;
    for (i=0; i<PicImage.length; i++) {
        piclist[i] = PicImage[i].attributes.filename;
        var j = 1;
        var CurrentImage;
        trace(“PicImage’s Length=”+PicImage.length);
        NextPicBtn.onRelease = function() {
            PrePicBtn.enabled = true;
            if (j<PicImage.length) {
                CurrentImage = j;
                startPreload(piclist[CurrentImage]);
                j++;
                if (j == PicImage.length) {
                NextPicBtn.enabled = false;
            }
            trace(“j=”+j);
            trace(“CurrentImage=”+CurrentImage);
            } else {
                break;
                PicStatus._visible = true;
                PicStatus.text = “This is The LAST!”;
            }
        };
        PrePicBtn.onRelease = function() {
            NextPicBtn.enabled = true;
            if (j<=PicImage.length && j>1) {
                CurrentImage–;
                startPreload(piclist[CurrentImage]);
                j–;
                if (j == 1) {
                    PrePicBtn.enabled = false;
                }
                trace(“j=”+j);
                trace(“CurrentImage=”+CurrentImage);
            } else {
                break;
                PicStatus._visible = true;
                PicStatus.text = “This is The FIRST!”;
            }
        };
    }
}
function startPreload(url) {
    PicLoader.loadMovie(url);
    onEnterFrame = preloadContents;
}
function preloadContents() {
    PicStatus._visible = true;
    LoadingBar._visible = true;
    var BytesLoaded = PicLoader.getBytesLoaded();
    var BytesTotal = PicLoader.getBytesTotal();
    var LoadPercent = int((BytesLoaded/BytesTotal)*100)+”%”;
    var ProgressBarnerLength = 600*(BytesLoaded/BytesTotal);
    LoadingBar.ProgressBarner._width = ProgressBarnerLength;
    PicStatus.text = LoadPercent;
    if (BytesLoaded == BytesTotal) {
        LoadingBar._visible = false;
        PicStatus._visible = false;
        PicLoader.onEnterFrame = function() {
            this._alpha += 10;
            if (_alpha>=100) {
                delete onEnterFrame;
            }
        };
        delete onEnterFrame;
    } else {
        PicLoader._alpha = 0;
    }
}

Leave a Comment.