AS3 Bug accessing FlashVars when using TLFTextField (Workaround)


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. package
  2. {
  3. import flash.display.Sprite;
  4. import flash.events.Event;
  5. import flash.display.LoaderInfo;
  6. import com.carlcalderon.arthropod.Debug;
  7.  
  8. public class TraceFlashVars extends Sprite
  9. {
  10.  
  11. public function TraceFlashVars():void
  12. {
  13. if (stage) init();
  14. else addEventListener(Event.ADDED_TO_STAGE, init);
  15. }
  16.  
  17. private function init(e:Event = null):void
  18. {
  19. removeEventListener(Event.ADDED_TO_STAGE, init);
  20.  
  21. Debug.clear();
  22. // Trace out all the FlashVars
  23. Debug.log("-- FLASHVARS --------------------------------");
  24. var keyStr:String;
  25. var valueStr:String;
  26.  
  27. //var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
  28. var paramObj:Object;
  29. paramObj = loaderInfo.parameters;
  30.  
  31. ////////////////////////////////////////////////////////////////////////////
  32. // This is work workaround for accessing FlashVars when using a TLFTextField
  33. if (parent != null && parent.parent != null) {
  34. paramObj = parent.parent.loaderInfo.parameters;
  35. }
  36. ////////////////////////////////////////////////////////////////////////////
  37.  
  38. var numOfFlashVars:int = 0;
  39. for (keyStr in paramObj) {
  40. valueStr = String(paramObj[keyStr]);
  41. Debug.log(keyStr + ": " + valueStr);
  42. numOfFlashVars++;
  43. }
  44.  
  45. Debug.log("---------------------------------------------");
  46. if (numOfFlashVars == 0) {
  47. Debug.log("No FlashVars were found!");
  48. } else {
  49. Debug.log(numOfFlashVars+" FlashVars were found.");
  50. }
  51. }
  52.  
  53.  
  54. }
  55.  
  56. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.