0

我收到此脚本的 2007 错误“参数文本必须为非空”。我认为这与数组有关,就好像我 trace(painterArray) 我得到“未定义”一样。我试过 String(painterArray[currPainting]) 但这只是给了我文本形式的“未定义”。

infoBox.alpha=1;
theImage.alpha=1;
loadingBar.visible = false;

//variables to hold the final coordinates of the image tween
var finalX:Number;
var finalY:Number;

//variable to hold the number of images in the XML
var listLength:Number;

//keeps track of what image should be displayed
var currPainting:Number=0;

//arrays to hold the contents of the XML, using this to allow
var imageArray:Array = new Array();
var painterArray:Array = new Array();
var titleArray:Array = new Array();
var dateArray:Array = new Array();

//Loader event for the XML

var xml:XML = <xml>
<images>
        <pic>images/3.png</pic>
        <en>Painter</en>
        <cn>画家</cn>
        <misc></misc>
</images>

</xml>


var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);

function loadXML():void {
    //load XML
    var il:XMLList=xml.images;
    listLength=il.length();

    //fill the empty arrays with XML items
    populateArray();
}

startButton.addEventListener(MouseEvent.CLICK, onStartClick);

function onStartClick(event:MouseEvent):void{
    populateArray();

    beginImage();
}   

function populateArray():void {
    //takes the properties defined in the XML and stores them 
    //into arrays
    var i:Number;
    for (i = 0; i < listLength; i++) {
        imageArray[i]=xml.images[i].pic;
        titleArray[i]=xml.images[i].cn;
        painterArray[i]=xml.images[i].en;
        dateArray[i]=xml.images[i].misc;
    }
}

function beginImage():void {

    //load description
    infoBox.theArtist.text=painterArray[currPainting];
    infoBox.theTitle.text=titleArray[currPainting];
    infoBox.theDate.text=dateArray[currPainting];

    theImage.scaleX=1;
    theImage.scaleY=1;

    var imageLoader = new Loader();

    //catches errors if the loader cannot find the URL path
    imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, catchFunction);
    //actually loads the URL defined in the image array
    imageLoader.load(new URLRequest(imageArray[currPainting]));
    //adds a listener for while the image is loading
    imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imgLoading);
    //adds a listener for what to do when the image is done loading
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);

    function catchFunction(e:IOErrorEvent) {
        trace("Bad URL: " + imageArray[currPainting] + " does not exist");
        //take out the bad URL from the array
        imageArray.splice(currPainting,1);
        titleArray.splice(currPainting,1);
        painterArray.splice(currPainting,1);
        dateArray.splice(currPainting,1);

        //check to see if there are images left,
        //else restart the slideshow
        if (imageArray.length==0) {
            populateArray();
        } else {
            beginImage();
        }
    }

    function imgLoaded(event:Event):void {
        loadingBar.visible = false;

        //add the image and get the dimensions to center the image
        theImage.addChild(imageLoader);
        //take the contents of the loaded image and cast it as bitmap data
        //to allow for bitmap smoothing
        var image:Bitmap = imageLoader.content as Bitmap;
        image.smoothing=true;
        theImage.x = (stage.stageWidth/2) - (imageLoader.content.width / 2);
        theImage.y = (stage.stageHeight/2) - (imageLoader.content.height / 2);

        finalX = (stage.stageWidth/2) - (imageLoader.content.width * .8 / 2);
        finalY = (stage.stageHeight/2) - (imageLoader.content.height * .8 / 2);

        //start tween function
        easeIn();

    }
}

function easeIn():void {
    TweenLite.to(theImage, 11.6, {scaleX:.8, scaleY:.8, x:finalX, y:finalY, onComplete:hideStuff});
    TweenLite.to(theImage, 1, {alpha:1, overwrite:0});
    TweenLite.to(infoBox, 1, {alpha:1});
}

function hideStuff():void {
    TweenLite.to(theImage, 1, {alpha:0, onComplete:nextImage});
    TweenLite.to(infoBox, 1, {alpha:0});
}

function nextImage():void {
    //take out the image that was just displayed by deleting the prev XML node
    imageArray.splice(currPainting,1);
    titleArray.splice(currPainting,1);
    painterArray.splice(currPainting,1);
    dateArray.splice(currPainting,1);

    //remove the picture
    theImage.removeChildAt(0);

    //start over
    if (imageArray.length==0) {
        //fill up array again
            populateArray();
    } else {
        beginImage();
    }
}

有谁知道这是什么原因造成的?

此外,如您所见,它还取决于外部图像文件。对于 100% 独立的 SWF,我如何对其进行编辑以便它使用库中的图像文件?我将每个图像作为库中的影片剪辑。

谢谢!

4

0 回答 0