我是新来的AS3.0,想完成我的项目。
我现在用的是跌破$ C $下我的XML幻灯片,但我想要的图片淡出对方应该永不褪色,完成白。希望哪位高手可以帮我。
导入GS *。
进口flash.display.Sprite;
进口flash.display.StageAlign;
进口flash.display.StageScaleMode;
进口对象类型:flash.events.Event;
进口fl.transitions.easing中*。
在Stage.scaleMode = StageScaleMode.NO_SCALE时;
stage.align = StageAlign.TOP_LEFT;
//隐藏说明框,直到图像加载
//隐藏图像,直到它被加载
theImage.alpha = 0;
loadingBar.visible = FALSE;
//变量来保存图像补间的最后坐标
VAR finalX:数字;
VAR finalY:数字;
//变量来保存在XML的图像数
VAR listLength:数字;
//跟踪什么样的形象应该显示的
VAR currPainting:数= 0;
//数组来保存的XML的内容,以此来允许
//为随机顺序图像
VAR imageArray:阵列=新的Array();
//装载机事件的XML
VAR装载机:的URLLoader =新的URLLoader();
loader.addEventListener(引发Event.COMPLETE,onLoaded);
VAR的xml:XML;
loader.load(新的URLRequest(画廊/ XML / maingallery.xml));
功能onLoaded(五:事件):无效{
//加载XML
XML =新的XML(e.target.data);
变种IL:返回XMLList = xml.images;
listLength = il.length();
populateArray();
}
功能populateArray():无效{
//需要在XML定义的属性和将它们存储
//为数组
变种我:数字;
对于(i = 0; I< listLength;我++){
imageArray [i] = xml.images [I] .PIC;
}
beginImage();
}
功能beginImage():无效{
//抓住介于0和数量的随机数
//数组中的图像
//负荷说明
VAR ImageLoader的=新的Loader();
//捕获错误,如果加载器无法找到URL路径
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,catchFunction);
//实际加载图像阵列中定义的URL
imageLoader.load(新的URLRequest(imageArray [currPainting]));
//添加了一个侦听器,而图像加载
imageLoader.contentLoaderInfo.addEventListener(使用ProgressEvent.PROGRESS,imgLoading);
//添加侦听适合做什么,当图像加载完成
imageLoader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,imgLoaded);
功能catchFunction(E:IOErrorEvent){
跟踪(坏网址:+ imageArray [currPainting] +不存在);
//从数组中取出不良网址
imageArray.splice(currPainting,1);
//检查,看看是否有剩余的图像,
//否则重新开始幻灯片放映
如果(imageArray.length == 0){
populateArray();
} 其他 {
beginImage();
}
}
功能imgLoading(事件:ProgressEvent):无效{
//显示加载栏,并更新宽度
//基于有多少是装
loadingBar.visible = TRUE;
loadingBar.bar.scale =(event.bytesLoaded / event.bytesTotal)* 100;
loadingBar.x = stage.stageWidth / 2;
loadingBar.y = stage.stageHeight - 400;
}
VAR widthRatio:数字;
VAR heightRatio:数字;
功能imgLoaded(事件:事件):无效{
loadingBar.visible = FALSE;
//添加图像,并获得尺寸图像居中
theImage.addChild(ImageLoader的);
如果(imageLoader.width> stage.stageWidth){
widthRatio = imageLoader.width / stage.stageWidth;
跟踪(widthRatio)
跟踪(imageLoader.width);
}
如果(imageLoader.height> stage.stageHeight - 207){
heightRatio = imageLoader.height /(stage.stageHeight - 207);
跟踪(heightRatio)
跟踪(imageLoader.height)
}
如果(widthRatio> heightRatio){
imageLoader.width = stage.stageWidth;
imageLoader.height = imageLoader.height / widthRatio;
} 其他 {
imageLoader.height = stage.stageHeight - 207;
imageLoader.width = imageLoader.width / heightRatio;
}
imageLoader.x =(imageLoader.stage.stageWidth / 2) - (imageLoader.width / 2);
imageLoader.y = 0
//把加载的图像的内容,将它转换为位图数据
//允许位图平滑
VAR图像:位图= imageLoader.content为位图;
image.smoothing = TRUE;
//开始补间功能
easeIn();
}
}
功能easeIn():无效{
TweenLite.to(theImage,5,{的onComplete:hideStuff});
TweenLite.to(theImage,1,{阿尔法:1,覆盖:0});
}
功能hideStuff():无效{
TweenLite.to(theImage,1,{阿尔法:0,的onComplete:NEXTIMAGE});
}
功能NEXTIMAGE():无效{
//拿出刚刚显示的图像
imageArray.splice(currPainting,1);
//删除图片
theImage.removeChildAt(0);
//重来
如果(imageArray.length == 0){
populateArray();
} 其他 {
beginImage();
}
}
解决方案
好吧,首先,你需要为你想在褪色的图像变量。让我们整理它,所以它是清楚哪个是哪个。
VAR theCurrentImage:的DisplayObject;
VAR theNextImage:的DisplayObject;
加载的第一张图像(现在 theCurrentImage
)的和以前一样以同样的方式。
现在这里是你如何可以加载下一个图像在阵列中的:
函数loadNextImage():无效{
currPainting ++;
//你还应该确保currPainting是不是出界这里
的LoadImage();
}
功能的LoadImage():无效{
ImageLoader的=新的Loader();
imageLoader.addEventListener(引发Event.COMPLETE,onImageLoaded);
//其他的侦听器放在这里太
imageLoader.load(新的URLRequest(imageArray [currPainting]));
}
功能onImageLoaded(五:事件):无效{
theNextImage = ImageLoader的; //存储下一个图像准备在褪去
theNextImage.alpha = 0;
的addChild(theNextImage); //现在可以交叉淡入
交叉淡入淡出();
}
功能交叉淡入淡出():无效{
TweenLite.to(theCurrentImage,1,{阿尔法:0});
TweenLite.to(theNextImage,1,{阿尔法:1});
//从舞台上删除theCurrentImage(今不可见)
removeChild之(theCurrentImage);
// theNextImage现在所显示的图像,...
theCurrentImage = theNextImage;
theNextImage = NULL;
//准备好通过调用loadNextImage加载下一个图像()
}
I am new to as3.0 and want to complete my project.
I am using the below code for my xml slideshow but I want the pictures to fade into each other it should never fade to complete white. Hope any expert can help me.
import gs.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import fl.transitions.easing.*;
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("galleries/xml/maingallery.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
//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.bar.scale = (event.bytesLoaded/event.bytesTotal)*100;
loadingBar.x = stage.stageWidth/2;
loadingBar.y = stage.stageHeight - 400;
}
var widthRatio:Number;
var heightRatio:Number;
function imgLoaded(event:Event):void {
loadingBar.visible = false;
//add the image and get the dimensions to center the image
theImage.addChild(imageLoader);
if (imageLoader.width > stage.stageWidth){
widthRatio=imageLoader.width/stage.stageWidth;
trace(widthRatio)
trace(imageLoader.width);
}
if (imageLoader.height > stage.stageHeight - 207){
heightRatio=imageLoader.height/(stage.stageHeight - 207) ;
trace(heightRatio)
trace(imageLoader.height)
}
if (widthRatio > heightRatio){
imageLoader.width = stage.stageWidth;
imageLoader.height = imageLoader.height/widthRatio;
} else {
imageLoader.height = stage.stageHeight - 207;
imageLoader.width = imageLoader.width/heightRatio;
}
imageLoader.x = (imageLoader.stage.stageWidth / 2) - (imageLoader.width / 2);
imageLoader.y = 0
//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, 5, {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();
}
}
解决方案
Ok, first you need to create a variable for the image you wish to fade in. Let's organise it so it is clear which is which.
var theCurrentImage:DisplayObject;
var theNextImage:DisplayObject;
Load in the first image (now theCurrentImage
) in the same way as before.
Now here's how you could load in the next image in the array:
function loadNextImage():void {
currPainting++;
// you should also make sure currPainting is not out of bounds here
loadImage();
}
function loadImage():void {
imageLoader = new Loader();
imageLoader.addEventListener(Event.COMPLETE, onImageLoaded);
// other listeners go here too
imageLoader.load(new URLRequest(imageArray[currPainting]));
}
function onImageLoaded(e:Event):void {
theNextImage = imageLoader; // stores the next image ready to be faded in
theNextImage.alpha = 0;
addChild(theNextImage); // now ready to be cross-faded in
crossFade();
}
function crossFade():void {
TweenLite.to(theCurrentImage, 1, {alpha:0});
TweenLite.to(theNextImage, 1, {alpha:1});
// remove theCurrentImage (now invisible) from the stage
removeChild(theCurrentImage);
// theNextImage is now the displayed image so...
theCurrentImage = theNextImage;
theNextImage = null;
// ready to load the next image by calling loadNextImage()
}