MovieClip Loop Control

?View Code ACTIONSCRIPT
1
2
3
4
5
6
import net.peteshand.utils.LoopCtrl;
LoopCtrl.setLoops(this,3,40); 
// Parameters:
   // Target MovieClip, 
   // Number of Loops, 
   // Frames of end of timeline to stop at (default = 0)
?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package net.peteshand.utils
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.EventDispatcher;
 
	public class LoopCtrl extends EventDispatcher
	{
		/** @private **/
		private static var ref:MovieClip;
		private static var loops:int;
 
		public function LoopCtrl ()
		{
 
		}
 
		public static function setLoops(_ref:MovieClip, _loops:int=1, preEndFrame:int=0):void
		{
			ref = _ref;
			loops = _loops;
			var count:int = 0;
 
			ref.addFrameScript(ref.totalFrames-1-preEndFrame, LastFrame);
			function LastFrame():void
			{
				count++;
				if (count == loops){
					ref.stop();
					ref.dispatchEvent(new Event("LoopEnd"));
				}
			}
		}
	}
}

Submit a Comment

Your email address will not be published. Required fields are marked *