AS3:Tween Lite:补间在完成之前停止?

edit2:我发现了什么问题。回答了我自己的问题。 *脸庞*对不起浪费空间。 (如果你随机看到这个,我的解决方案在底部回答) 编辑:在仔细考虑我的代码试图找到一个解决方案时,我注意到当我的.swf冻结,因为它正在补间时,舞台上的动画电影剪辑也冻结了动画中期。这让我相信我的问题可能源于我的代码的加载/创建图像部分。因此,这是我的加载函数,以补充下面的代码:
function loadImage():void {

    //if it's not already been loaded)
    if ((currentImageNbr+1) > imagesLoaded || images.length == 0) {

        imagesLoaded++;

        tempPic = xmlData.album[albumNum].image[currentImageNbr].attribute("file");
        tempCaption = xmlData.album[albumNum].image[currentImageNbr].attribute("caption");
        trace("Loading: "+galleryPath+tempPic+" ("+tempCaption+")");

        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, catchIOError);

        loader.load(new URLRequest(galleryPath+tempPic));
        images[currentImageNbr] = loader;
        paths[currentImageNbr] = tempPic;
        captions[currentImageNbr] = tempCaption;
        //loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImgProgress); (not incorporated yet.)

        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImgComplete);
    }
    else {
        trace("image already loaded.");
        onImgComplete(null);
    }
}
原帖: 嗨再次StackOverflow! 这对我解释我的问题可能有点棘手,所以如果我没有多大意义,请幽默我。 我正在尝试创建一个(简单的......)XML图像库。 XML和加载部分(在大多数情况下)是精细和花花公子。我的问题是使用greensock的TweenLite让我的照片滑入和滑出舞台。 我想要实现的动议有点像这样: 从舞台右侧创建我的图像 从右边旋转,停在舞台的中央 然后当我切换到下一张图片时,我希望当前的图像从左边的舞台中旋转出来 被删除 在右侧舞台外创建一个新幻灯片 最后,从右边旋转 等等 当我在flash中使用
Ctrl + Enter
运行它时,我的代码工作正常,但是当我在浏览器中运行.swf时,图像在很多时候都无法正确滑动。 他们经常停下来,中间“旋转”,不要移动几秒钟 然后它们消失,下一个图像突然出现在中心而没有任何补间发生。 我有一个预感(根据我读过的类似问题),我的问题与我有关,错误地使用相同的补间为下一个,并在中间补间收集垃圾.. 我仍然很擅长使用TweenLite,所以我不太了解它的来龙去脉...... 也许我没有正确创建我的补间? 以下是我认为可能是问题区域的一些相关代码片段, 如果你发现我使用的是错误的方法或错误,请告诉我,我还在学习ActionScript 3: 一些先决条件(这可能很重要?)
import com.greensock.*;
import com.greensock.easing.*;

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

stage.addEventListener(Event.RESIZE, resizeHandler, false, 0, true);
加载我的图像(这个函数里面有更多内容,但我对此部分并不感到烦恼)
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImgComplete);
加载后:
function onImgComplete(e:Event):void {
    trace("loading done");

    // check if containerSp exists on stage 
    // if it does, tween it, on complete- delete it and make a new one.
    if (containerSp.stage) {
        trace("containerSp already exists. removing, then making a fresh one");

        // need to check if we're going forwards or backwards.
        if (leftRight == "right") {
            //forwards
            trace("tweening out..");
            moving = true;

            TweenLite.to(containerSp, .5, {x:0-(containerSp.width+20), y:containerSp.y, ease:Quint.easeIn, onComplete:removeSprite}); 
        }
        else if (leftRight == "left") {
            //backwards
            trace("tweening out..");
            moving = true;

            TweenLite.to(containerSp, .5, {x:stage.stageWidth+20, y:containerSp.y, ease:Quint.easeIn, onComplete:removeSprite});
        }
    }
    else {
        trace("containerSp doesn't exist. making a fresh one.");
        makeSprite();
    }
}
完成补间后,删除图像并制作一个新的精灵:
function removeSprite():void {
    moving = false;
    stage.removeChild(containerSp);
    makeSprite();
}
在containerSp中创建我的图像(尚未添加到舞台中):
function makeSprite():void {
    containerSp = new Sprite();
    containerSp.graphics.beginFill(0xFF0000);
    containerSp.graphics.drawRect( 0, 0, 0, 0);
    trace("Done.");

    trace("making image");
    var bm:Bitmap = new Bitmap();
    bm = Bitmap(images[currentImageNbr].content);
    bm.smoothing = true;

    containerSp.addChild(bm);

    trace("done");
    tweenIn();
}
设置我们的containerSp的位置,将其添加到舞台并将其补间:
function tweenIn():void {
    moving = true;
    resizeHandler();

    // need to check if we're going forwards or backwards.
    if (leftRight == "right") {
        //forwards
        containerSp.y = (stage.stageHeight/2)-(containerSp.height/2)-(barHeight/2);
        containerSp.x = stage.stageWidth;
    }
    else if (leftRight == "left") {
        //backwards
        containerSp.y = (stage.stageHeight/2)-(containerSp.height/2)-(barHeight/2);
        containerSp.x = (0 - stage.stageWidth);
    }

    stage.addChild(containerSp);

    trace("tweening in..");

    TweenLite.to(containerSp, .5, {x:(stage.stageWidth/2)-(containerSp.width/2), y:(stage.stageHeight/2)-(containerSp.height/2)-(barHeight/2), ease:Quint.easeOut, onComplete:done}); 
}

function done():void {
    trace("all done");
    moving = false;
    resizeHandler();
}
使用
resizeHandler
是在重新调整窗口大小时重新调整图片大小。 它基本上相对于框架的大小设置
containerSp.width
.height
.x
.y
moving
变量为
resizeHandler
,因此除非图像不移动,否则不会将
X
Y
设置为舞台中心。 总结一下我的问题,为什么补间只有在我在浏览器中加载.swf时才会在完成之前停止工作? 如果我忘记提及任何事情,请告诉我,我会很乐意填写空白。 提前感谢您的时间和耐心。     
已邀请:
你试过killTweensOf()方法吗?     
所以这根本不是TweenLite的错。结果我加载的图像的大小不是Web友好的;哪个flash无法处理(至少在我的lappy上)。所以即使在我将图像加载到缓存和所有内容之后,当我将一个MovieClip的庞然大物添加到舞台时,.swf会在试图保持时挂起工作。所以补间实际上是正确触发的。我通过制作一个40x40 .gif的小型原型并将其应用到我的项目中找到了所有这些。 作为一种解决方案(除了缩小和优化我的图像),在加载新图像时,而不是将其添加到前一个图像被删除后的阶段(即使它已经加载)我已经将它添加到舞台上作为加载过程的一部分,以便在添加影片剪辑时没有补间看起来很丑陋。 无论如何,感谢任何查看我的代码和/或线程的人。还有一些建议本来不错,但我意识到这篇文章相当庞大而乏味。     

要回复问题请先登录注册