单击补间中的文本元素会停止动画

发布于 2024-09-25 20:18:51 字数 1935 浏览 6 评论 0原文

我在补间方面遇到了一些麻烦。这是我的用法的描述:

我有一个系统,其中文本框是影片剪辑的子项。当您单击“下一步”按钮时,影片剪辑会淡入 0-alpha,完成后,文本框中的文本将更改(更改为数组中的下一个索引),并补间回到 100-alpha。这在文本中实现了很好的过渡。

我的问题是,有时它不会补间回来,只会补间出来,给用户留下一个文本应该在的空框。

然而,我之前问过这个问题,认为这是“超时”。现在,经过大量测试,我意识到只有当我单击或选择文本框中的某些文本时才会发生这种情况。它是否与干扰下面的changeText函数的文本选择有关...(它是相同的文本框,只是文本发生了变化)。

还有其他人遇到过类似的故障吗?

代码:

function changeClick(e:MouseEvent):void {
    if (e.currentTarget==btnRight) {
        newDirect="right";
    } else {
        newDirect="left";
    }
    if (newDirect=="right") {
        if (pageTotal!=pageCurrent) {
            tweenText=new Tween(b_textB,"alpha",Strong.easeOut,1,0,.5,true);
            tweenText.addEventListener(TweenEvent.MOTION_FINISH, changeText);
        }
    } else {
        if (pageCurrent!=1) {
            tweenText=new Tween(b_textB,"alpha",Strong.easeOut,1,0,.5,true);
            tweenText.addEventListener(TweenEvent.MOTION_FINISH, changeText);
        }
    }
}

function changeText(e:TweenEvent):void {
    var newText:String;
    var pageCurrentConstant:int=pageCurrent;
    if (newDirect=="right") {
        for (var i=0; i<=(pageTotal-1); i++) {
            if ((pageCurrentConstant-1)==i) {
                if (i!=pageTotal-1) {
                    newText=pageText[i+1];
                    pageCurrent++;
                } else {
                    newText=pageText[i];
                }
            }
        }
    } else {
        for (var j=0; j<=pageTotal; j++) {
            if (pageCurrentConstant==j) {
                if (j!=0) {
                    newText=pageText[j-2];
                    pageCurrent--;
                } else {
                    newText=pageText[j];
                }
            }
        }
    }
    b_textB.htmlText=newText;
    tweenText=new Tween(b_textB,"alpha",Strong.easeOut,0,1,.5,true);
    drawWidget();
}

changeClick 由 btnRight 或 btnLeft 启动以导航文本

I've been having some trouble with tweens. Here's a description of my usage:

I have a system where a textbox is the child of a movieclip. When you click the "Next" button, the movieclip fades to 0-alpha and upon completion, the text in the textbox is changed (to the next index in an array) and it tweens back in to 100-alpha. This makes a nice transition through the text.

My issue is that sometimes it doesn't tween back in, only out, leaving the user with an empty box where text should be.

However, I'd asked this question previously with the thought that it was "Timing out". Now, after significant testing I realised that it only happens if I click or select some of the text on the text box. Could it have something to do with this text selection intefering with the changeText function below... (it's the same text box, just the text changes).

Has anyone else experienced similar faults?

CODE:

function changeClick(e:MouseEvent):void {
    if (e.currentTarget==btnRight) {
        newDirect="right";
    } else {
        newDirect="left";
    }
    if (newDirect=="right") {
        if (pageTotal!=pageCurrent) {
            tweenText=new Tween(b_textB,"alpha",Strong.easeOut,1,0,.5,true);
            tweenText.addEventListener(TweenEvent.MOTION_FINISH, changeText);
        }
    } else {
        if (pageCurrent!=1) {
            tweenText=new Tween(b_textB,"alpha",Strong.easeOut,1,0,.5,true);
            tweenText.addEventListener(TweenEvent.MOTION_FINISH, changeText);
        }
    }
}

function changeText(e:TweenEvent):void {
    var newText:String;
    var pageCurrentConstant:int=pageCurrent;
    if (newDirect=="right") {
        for (var i=0; i<=(pageTotal-1); i++) {
            if ((pageCurrentConstant-1)==i) {
                if (i!=pageTotal-1) {
                    newText=pageText[i+1];
                    pageCurrent++;
                } else {
                    newText=pageText[i];
                }
            }
        }
    } else {
        for (var j=0; j<=pageTotal; j++) {
            if (pageCurrentConstant==j) {
                if (j!=0) {
                    newText=pageText[j-2];
                    pageCurrent--;
                } else {
                    newText=pageText[j];
                }
            }
        }
    }
    b_textB.htmlText=newText;
    tweenText=new Tween(b_textB,"alpha",Strong.easeOut,0,1,.5,true);
    drawWidget();
}

changeClick is initiated by either btnRight or btnLeft to navigate through the text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生死何惧 2024-10-02 20:18:51

尝试使用 b_textB.selectable = false 禁用文本选择,

您将能够快速排除选择问题的可能性。但您问题中的有时强烈表明问题所在。

如果您需要在可见时选择文本,只需在补间的开始和结束时将其关闭和打开即可。

希望这能解决它。

哦,顺便说一句,这里列出了 Tween 类的几个完全免费的替代品...(Greensock 的 Tween 包不是免费的。)

更新...

解决此问题并允许用户选择文本的唯一方法是创建一个可选择的重复文本字段,并在补间开始时关闭此选项,并且当它结束时再次打开,受影响的 textfield 上的 alpha 属性将正常工作。

我知道这很笨拙,但它会产生效果,并允许用户在文本可见时选择它。

您也可以尝试将原始的 textfield 包装在 Sprite 中,并对其执行 alpha Tween,但我不保证这会100%修复。

Try disabling the text selection, with b_textB.selectable = false

You will be able to quickly rule out the possibility of a selection issue. But the sometimes in your question strongly indicates that's what the issue is.

If you need the text to be selectable when it's visible, just switch it off and on at the start and end of the tweens.

Hope this solves it.

Oh by the way, here's a list of several completely free alternatives to the Tween class... (Greensock's Tween packages are not free.)

Update...

The only way you can solve this and allow the user to select the text, is to make a duplicate textfield that's selectable, and toggle visible off for this when the tween begins and on again when it ends, the alpha property on the effected textfield will then work properly.

Pretty kludgy I know, but it will get the effect to work, and allow the user to select the text when it's visible.

You may also try to wrap the original textfield in a Sprite and do the alpha Tween on that instead, however I don't guarantee that will be a 100% fix.

夏日浅笑〃 2024-10-02 20:18:51

标准的 Tween 类在很多情况下都有点愚蠢。使用它时,您必须小心不要覆盖或删除它的实例,因为垃圾收集可能会启动。同样,它总是要求您指定一个可能导致动画行为中断的起始值。

我不太确定您的问题到底是什么,并且使用较少的代码很难重现它(如果您仍然遇到问题,您可能需要提供完整的工作示例代码)。不过我建议您尝试不同的补间框架。我自己在 Greensock 的 TweenLite 方面获得了非常好的体验。它可能有一种奇怪的语法(至少我可以想象出更好的语法),但总的来说它工作得很好,并且我通过简单地使用 TweenLite 解决了标准 Tween 类的很多问题。

The standard Tween class is kind of stupid in many situations. When using it, you have to be careful that you don't overwrite or remove its instance, as the Garbage Collection could start then. In the same way it always requires you to specify a start value which can lead to disrupting behaviour in the animation.

I'm not exactly sure what exactly your problem is, and with that less code it is hard to reproduce it (you might want to provide a full working example code if you still experience the problem). However I suggest you to try out a different tweening framework. I for myself have made very good experience with Greensock's TweenLite. It might have a weird syntax (at least I could imagine a better one), but in general it works really well, and I have solved very many problems with the standard Tween class by simply using TweenLite instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文