Return to Snippet

Revision: 36945
at December 1, 2010 04:10 by adrianparr


Initial Code
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.LoaderInfo;
    import com.carlcalderon.arthropod.Debug;

    public class TraceFlashVars extends Sprite
    {
       
        public function TraceFlashVars():void
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			Debug.clear();
			// Trace out all the FlashVars
			Debug.log("-- FLASHVARS --------------------------------");
			var keyStr:String;
			var valueStr:String;
			
			//var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
			var paramObj:Object;
			paramObj = loaderInfo.parameters;
			
			////////////////////////////////////////////////////////////////////////////
			// This is work workaround for accessing FlashVars when using a TLFTextField
			if (parent != null && parent.parent != null) {
				paramObj = parent.parent.loaderInfo.parameters;
			}
			////////////////////////////////////////////////////////////////////////////
			
			var numOfFlashVars:int = 0;
			for (keyStr in paramObj) {
				valueStr = String(paramObj[keyStr]);
				Debug.log(keyStr + ": " + valueStr);
				numOfFlashVars++;
			}
			
			Debug.log("---------------------------------------------");
			if (numOfFlashVars == 0) {
				Debug.log("No FlashVars were found!");
			} else {
				Debug.log(numOfFlashVars+" FlashVars were found.");
			}
		}
		

    }

}

Initial URL
http://www.adrianparr.com/?p=137

Initial Description
Note: This example uses Arthropod Debugger (AIR App) which can be downloaded from here http://arthropod.stopp.se/

Initial Title
AS3 Bug accessing FlashVars when using TLFTextField (Workaround)

Initial Tags
debug

Initial Language
ActionScript 3