-
for loop and caurina transitions question
Hello,
I have dozen movieclips in library which I want to attach and load dinamicaly. For this task I decided to attach them using for loop. Also I use caurina transitions to fade them in and out of stage. My problem is, that I want to loop them infinitely. To do that I put oll the code inside a function, and on the last movieclip that is coming on stage I put oncomplete function. Here is my code:
Actionscript Code:
startTween1 = function() {
for (i=1;i<16;i++){ _root.attachMovie("mc_txt"+i, "mc_txt"+i, i, {_x:150, _y:18}); _root["mc_txt"+i]._alpha = 0; Tweener.addTween(_root["mc_txt"+i], {_alpha:100, time:0.5, _x:15, delay:(i-1)*4.3, transition:"easeOutExpo" }); Tweener.addTween(_root["mc_txt"+i], {_alpha:0, time:0.5, _x:150, delay:(i-1)*4.3+4, transition:"easeInOutBack" }); }
_root.attachMovie("mc_txt16", "mc_txt16", 999, {_x:150, _y:10}); mc_txt6._alpha = 0; Tweener.addTween(mc_txt6, {_alpha:100, time:0.5, _x:3, delay:22 }); Tweener.addTween(mc_txt6, {_alpha:0, time:0.5, _x:-150, delay:25.5, onComplete:startTween1}); }
startTween1();
So, on the last movieclip (mc_txt16) I use this function onComplete:startTween1 to loop all the code infinitely. This works ok, but maybe there is a better solution for this? I've just searched this forum to find something like onCompleteselect the last movieclip in the for loop and then start startTween1 function) instead of adding several code lines that do the same as the for loop above.
Thanks...
-
Actionscript Code:
import caurina.transitions.Tweener; startTween1 = function() { var num:Number = 1; for (i=1;i<16;i++){ _root.attachMovie("mc_txt"+i, "mc_txt"+i, i, {_x:150, _y:18}); _root["mc_txt"+i]._alpha = 0; Tweener.addTween(_root["mc_txt"+i], {_alpha:100, time:0.5, _x:15, delay:(i-1)*4.3, transition:"easeOutExpo" }); Tweener.addTween(_root["mc_txt"+i], {_alpha:0, time:0.5, _x:150, delay:(i-1)*4.3+4, transition:"easeInOutBack" , onComplete:function() { num==15?startTween1():num++; }}); }
}
startTween1();
gparis
-
Thanks, completely solved my problem
Due to my basic knowledge of actionscript, maybe you can add some explanation what have you done here? I mean what this variable Number and function ( num==15?startTween1():num++; ) means?
-
The variable num increments by one each time one Tween ends (which i does not do). When (if) its total is equal to 15, when the last loop is done, it starts over. The last function is just shorthand for an if else. In simple english: if num equals 15, start the loop again, else increment num by 1.
gparis
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|