DoLaterUtil.as

Go to the documentation of this file.
00001 import gugga.crypt.GUID;
00002 import gugga.utils.DebugUtils;
00003 
00007 class gugga.utils.DoLaterUtil 
00008 {
00009         private static var mOnEnterFrameBeacon : MovieClip;
00010         private static var mDoLaterMethods : Array;
00011         
00012         public static function doLater(aScopeObject:Object, aMethod:Function, aArguments:Array, aFramesDelay:Number)
00013         {
00014                 if(!mOnEnterFrameBeacon)
00015                 {
00016                         var guid : String = GUID.create();
00017                         mOnEnterFrameBeacon = _level0.createEmptyMovieClip("OnEnterFrameBeacon_" + guid, _level0.getNextHighestDepth());
00018                 }
00019                 
00020                 if(!mDoLaterMethods)
00021                 {
00022                         mDoLaterMethods = new Array();
00023                 }
00024                 
00025                 var framesDelay:Number = 1;
00026                 
00027                 if(aFramesDelay)
00028                 {
00029                         framesDelay = aFramesDelay;
00030                 }
00031                 
00032                 var doLaterMethodDescriptor : Object = {
00033                         scopeObject: aScopeObject,
00034                         method: aMethod,
00035                         arguments: aArguments,
00036                         framesDelay: framesDelay
00037                 };
00038                 
00039                 mDoLaterMethods.push(doLaterMethodDescriptor);
00040                 
00041                 mOnEnterFrameBeacon.onEnterFrame = onBeaconEnterFrame;
00042         }
00043                 
00044         private static function onBeaconEnterFrame() : Void 
00045         {
00046                 if(mDoLaterMethods.length == 0)
00047                 {
00048                         mOnEnterFrameBeacon.onEnterFrame = null;
00049                 }
00050                 
00051                 var doLaterMethodDescriptor : Object;
00052                 for (var i:Number = 0; i < mDoLaterMethods.length; i++)
00053                 {
00054                         doLaterMethodDescriptor = mDoLaterMethods[i];
00055                         
00056                         doLaterMethodDescriptor.framesDelay--;
00057                         if(doLaterMethodDescriptor.framesDelay <= 0)
00058                         {
00059                                 doLaterMethodDescriptor.method.apply(doLaterMethodDescriptor.scopeObject, doLaterMethodDescriptor.arguments);
00060                                 mDoLaterMethods.splice(i, 1);
00061                         }
00062                 }
00063         }
00064 }

Generated on Fri May 11 17:12:42 2007 for GuggaFramework by  doxygen 1.5.2