Hello,
I’m struggling to debug the following piece of code. It is supposed to loop over some pictures and smoothly put each picture on top of the other. When NOT using the Tween transition (only [COLOR=royalblue]blue[/COLOR] statement below is used), it works perfectly. When using Tween transition (only [COLOR=red]red[/COLOR] statement below is used), it only works for the first loop: last picture’s _alpha property cannot be reset to zero. Once on the second loop, the last image’s _alpha property is still 100…
Thanks in advance for your help!
[FONT=Courier New][SIZE=1]import mx.transitions.Tween;[/SIZE][/FONT]
[SIZE=1][FONT=Courier New]import mx.transitions.easing.Strong;[/FONT][/SIZE]
[FONT=Courier New][SIZE=1]var nbPic:Number = 3;[/SIZE][/FONT]
[SIZE=1][FONT=Courier New]var counter:Number = 0;[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]var interval:Number = 3000;[/FONT][/SIZE]
[FONT=Courier New][SIZE=1]function fadeIn() {[/SIZE][/FONT]
[SIZE=1][FONT=Courier New]counter += 1;[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]if (counter<=nbPic) {[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]var currImg:MovieClip = eval(“pic”+counter);[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]//use tween[/FONT][/SIZE]
[FONT=Courier New][SIZE=1][COLOR=red]var myTween:Tween = new Tween(currImg, “_alpha”, Strong.easeOut, 0, 100, 36, false);[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=red][COLOR=black]//or no transition[/COLOR][/COLOR][/SIZE][/FONT][COLOR=red]
[/COLOR][SIZE=1][FONT=Courier New][COLOR=royalblue]currImg._alpha = 100;[/COLOR][/FONT][/SIZE]
[SIZE=1][FONT=Courier New]} else if (counter == nbPic+1) {[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]counter = 0;[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]resetPic();[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
[FONT=Courier New][SIZE=1]function resetPic() {[/SIZE][/FONT]
[SIZE=1][FONT=Courier New]for (var k:Number = nbPic; k>=1; k–) {[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]var pict:MovieClip = eval(“pic”+k);[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]pict._alpha = 0;[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
[FONT=Courier New][SIZE=1]//Main code[/SIZE][/FONT]
[SIZE=1][FONT=Courier New]for (var i:Number = 1; i<=nbPic; i++) {[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]this.attachMovie(“pic”+i,“pic”+i,i);[/FONT][/SIZE]
[SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
[FONT=Courier New][SIZE=1]resetPic();[/SIZE][/FONT]
[FONT=Courier New][SIZE=1]setInterval(fadeIn,interval);[/SIZE][/FONT]