Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3XML幻灯片放映_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 AS3XML幻灯片放映

Actionscript 3 AS3XML幻灯片放映,actionscript-3,flash,Actionscript 3,Flash,下面是我的幻灯片代码,我遇到的问题是,在第一个图像加载后,有我需要的完美大小,但第二个图像加载有不同的大小,我希望它的大小与第一个相同。此外,图像也没有按顺序加载。任何专家都能找出并解决这个问题 stop(); import gs.*; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; stag

下面是我的幻灯片代码,我遇到的问题是,在第一个图像加载后,有我需要的完美大小,但第二个图像加载有不同的大小,我希望它的大小与第一个相同。此外,图像也没有按顺序加载。任何专家都能找出并解决这个问题

stop();
import gs.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

//hides the description box until the image is loaded
//hides the image until it is loaded

theImage.alpha=0;
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
//for the random order of the images
var imageArray:Array = new Array();


//Loader event for the XML
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

var xml:XML;

loader.load(new URLRequest("paintings.xml"));

function onLoaded(e:Event):void {
//load XML
xml=new XML(e.target.data);
var il:XMLList=xml.images;
listLength=il.length();

populateArray();
}

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;

}
beginImage();
}

function beginImage():void {
//grabs a random number between 0 and the number
//of images in the array
currPainting=Math.floor(Math.random()*imageArray.length);

//load description

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);


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

function imgLoading(event:ProgressEvent):void{
    //show the loading bar, and update the width
    //based on how much is loaded
    loadingBar.visible = true;
    loadingBar.x = stage.stageWidth/2;
    loadingBar.y = stage.stageHeight/3
    loadingBar.bar.width = (event.bytesLoaded/event.bytesTotal)*100;
}

function imgLoaded(event:Event):void {
    loadingBar.visible = false;
    var scale:Number =  stage.stageWidth * 0.292708 / theImage.width;
    //add the image and get the dimensions to center the image
    theImage.addChild(imageLoader);
    theImage.x = stage.stageWidth/2.85;
    theImage.y = 0;

    if(theImage.height * scale > stage.stageHeight){
    scale = stage.stageHeight * 0.704918 / theImage.height;
    }   

    // apply the scale to the image
    theImage.scaleX = theImage.scaleY = scale;


    //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;
            //start tween function
    easeIn();
}
}

function easeIn():void {

TweenLite.to(theImage, 8, {onComplete:hideStuff});
TweenLite.to(theImage, 1, {alpha:1, overwrite:0});
}

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

}


function nextImage():void {
//take out the image that was just displayed
imageArray.splice(currPainting,1);


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

//start over
if (imageArray.length==0) {
    populateArray();
} else {
    beginImage();
}
}
stop();
进口gs.*;
导入flash.display.Sprite;
导入flash.display.StageAlign;
导入flash.display.StageScaleMode;
导入flash.events.Event;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP\u左;
//隐藏描述框,直到加载图像
//隐藏图像,直到加载为止
图像α=0;
loadingBar.visible=false;
//用于保存图像之间最终坐标的变量
var finalX:数字;
var最终:数量;
//变量来保存XML中的图像数
var listLength:数字;
//跟踪应显示的图像
变量:数值=0;
//数组来保存XML的内容,使用它来允许
//对于图像的随机顺序
var imageArray:Array=newarray();
//XML的加载程序事件
变量加载器:URLLoader=新的URLLoader();
loader.addEventListener(Event.COMPLETE,onload);
var-xml:xml;
load(新的URLRequest(“paints.xml”);
已加载函数(e:事件):无效{
//加载XML
xml=新的xml(e.target.data);
var-il:XMLList=xml.images;
listLength=il.length();
populateArray();
}
函数populateArray():void{
//获取XML中定义的属性并存储它们
//成阵列
变量i:数量;
对于(i=0;i舞台高度){
比例=舞台高度*0.704918/图像高度;
}   
//将比例应用于图像
theImage.scaleX=theImage.scaleY=比例;
//获取加载图像的内容并将其转换为位图数据
//允许位图平滑
var image:Bitmap=imageLoader.content作为位图;
图像平滑=真;
//启动tween函数
easeIn();
}
}
函数easeIn():void{
TweenLite.to(theImage,8,{onComplete:hideStuff});
to(图像,1,{alpha:1,overwrite:0});
}
函数hideStuff():void{
TweenLite.to(图像,1,{alpha:0,onComplete:nextImage});
}
函数nextImage():void{
//取出刚才显示的图像
图像阵列拼接(1);
//删除图片
图像移除Childat(0);
//重新开始
if(imageArray.length==0){
populateArray();
}否则{
beginImage();
}
}
这是xml

    <xml>
            <images><pic>portfolio1.jpg</pic></images>
            <images><pic>portfolio2.jpg</pic></images>
            <images><pic>portfolio3.jpg</pic></images>
            <images><pic>portfolio4.jpg</pic></images>
            <images><pic>portfolio5.jpg</pic></images>

    </xml>

portfolio1.jpg
portfolio2.jpg
portfolio3.jpg
portfolio4.jpg
portfolio5.jpg

我不认为图像的高度代表加载后的图像高度。这应该是可用的加载器。为了适应不同大小的图像,您必须在应用缩放时提供图像的实际高度/宽度。当然,也可以将所有图像的大小预先调整为相同的大小

关于随机加载,这正是

currPainting=Math.floor(Math.random()*imageArray.length);

beginImage
中正在执行。要按顺序加载,可以直接拾取第0个元素。

为什么不在flash之外使图像大小相同?