【问题标题】:flash / Actionscript - .alpha property not always workingflash / Actionscript - .alpha 属性并不总是有效
【发布时间】:2014-02-02 23:00:28
【问题描述】:

我正在修复别人的代码,一切都完成了 Flash CS5 上的 actionscript 3.0。这是动作脚本:

var buttons = ["suspend", "dissolve"];
// there are two buttons on the screen. One says 'Suspend' and the other says 'dissolve'.
// When 'suspend' is clicked, information on the word 'suspend' fades in onto the screen
// and, if information on the word 'dissolve' is on the screen, it disappears.

// When 'dissolve' is clicked, information on the word 'dissolve' fades in onto the screen
// and, if information on the word 'suspend' is on the screen, it disappears.

// the code below explains this:

function changeContent (mc:MovieClip):void{

for (var i: int = 0; i < buttons.length ; i++){
    if (buttons[i].associated == mc){ // if 'suspend' or 'dissolve' is clicked
        tweenA = new Tween (buttons[i].associated, "alpha", Strong.easeOut, buttons[i].associated.alpha, 1, tweenSpeed, false); 
        // the line above makes the information corresponding to the button fade in

    }else{
        buttons[i].associated.alpha = 0; // otherwise make the information corresponding to the button disappear
    }
}
checkDone (); // checks if both buttons are clicked.. this part works fine
}

现在,此动画有效,当我单击“暂停”时,“暂停”信息消失在视图中,而溶解信息消失,反之亦然。但是,如果单击“暂停”,然后很快单击“溶解”(如果我一个接一个地单击两个按钮,非常快),则“暂停”信息和“溶解”信息但出现并重叠彼此。好像这条线

buttons[i].associated.alpha = 0; // this line is supposed to make the button which
                                 // isn't clicked disappear

如果两个按钮一个接一个地点击就不起作用,真的很快。知道如何解决这个问题吗?

【问题讨论】:

    标签: actionscript-3 flash alpha-transparency


    【解决方案1】:

    您有一个具有持续时间的补间动画和一个设置补间属性的语句,因此您会遇到这样一种情况,即您的代码的两部分更改了一个变量,但不知道它在其他地方被更改。解决方法是在设置 alpha 之前停止补间。

        }else{  
            if (tweenA.isPlaying) tweenA.stop(); // there!
            buttons[i].associated.alpha = 0; // otherwise make the information corresponding to the button disappear
        }
    

    但是您需要避免一个变量与多个可以同时更改的对象相关的情况,例如您希望“暂停”和“溶解”相关的文本同时淡入(可能在不同的地方)并且您补间只有一个变量,您不能同时控制它们。在这里我们遇到了同样的事情:使用此代码,您将无法淡入除最后一个按钮之外的任何文本!这是因为我们对所有可能的补间使用tweenA,即使在特定时间只能有一个活动。所以,我们必须再修复它一点。

    var tweenB:Tween; // a temporary tween for a new fade in animation
    for (var i: int = 0; i < buttons.length ; i++){
        if (buttons[i].associated == mc){ // if 'suspend' or 'dissolve' is clicked
            tweenB = new Tween (buttons[i].associated, "alpha", Strong.easeOut, buttons[i].associated.alpha, 1, tweenSpeed, false); 
            // the line above makes the information corresponding to the button fade in
            // and now we store a new tween in another var so that it won't be stopped at once
        }else{  
            if (tweenA && tweenA.isPlaying) tweenA.stop(); // And here we stop old tween
            // also protecting self from 1009 if no tween was stored yet
            buttons[i].associated.alpha = 0; // otherwise make the information corresponding to the button disappear
        }
    }
    tweenA=tweenB; // store newly created tween, if any (!) into our current tween var
    

    【讨论】:

    • 编辑:啊,你在 tweenB 中存储了一个新的补间,天才!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 2015-06-28
    • 2015-12-04
    • 2017-01-08
    相关资源
    最近更新 更多