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)

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"));
				}
			}
		}
	}
}