Actionscript 3 flash/Actionscript-.alpha属性不总是工作
我正在修改别人的代码,所有的工作都是在Flash CS5上完成的actionscript 3.0。以下是操作脚本:Actionscript 3 flash/Actionscript-.alpha属性不总是工作,actionscript-3,flash,alpha-transparency,Actionscript 3,Flash,Alpha Transparency,我正在修改别人的代码,所有的工作都是在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'
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
}
如果两个按钮一个接一个地单击,则无法正常工作,速度非常快。你知道如何解决这个问题吗?你有一个有持续时间的tween动画,还有一个设置tween属性的语句,所以你的代码中有两个部分改变了一个变量,而不知道它在其他地方被改变了。解决方案是在设置alpha之前停止吐温
}else{
if (tweenA.isPlaying) tweenA.stop(); // there!
buttons[i].associated.alpha = 0; // otherwise make the information corresponding to the button disappear
}
但您需要避免一个变量与多个可以同时更改的对象相关的情况,比如您希望关联的“暂停”和“溶解”文本同时淡入(可能在不同的位置),并且二者之间只有一个变量,您无法同时控制它们。在这里,我们遇到了同样的事情:使用此代码,除了最后一个按钮外,您将无法淡入任何文本!这是因为我们对所有可能的tween使用tweenA
,即使在特定时间只有一个活动tween。所以,我们必须再修一点
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
var-tweenB:Tween;//用于新淡入动画的临时二人组
对于(变量i:int=0;i
EDIT:啊,你在tweenB中存储了一个新的tween,天才!谢谢
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