AS3 Loader Garbage Collection


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



Copy this code and paste it in your HTML
  1. import flash.display.Loader;
  2. import flash.utils.Timer;
  3. import flash.events.TimerEvent;
  4. import flash.system.ApplicationDomain;
  5. import flash.system.LoaderContext;
  6. import flash.system.System;
  7. import flash.net.LocalConnection;
  8.  
  9. var t : Timer = new Timer(500);
  10. var l : Loader = new Loader();
  11.  
  12. var lc : LoaderContext = new LoaderContext();
  13. lc.applicationDomain = new ApplicationDomain();
  14.  
  15. t.addEventListener(TimerEvent.TIMER, fOnTimer);
  16. t.start();
  17. addChild(l);
  18.  
  19. function fOnTimer(e : TimerEvent) : void
  20. {
  21. if (l.content != null)
  22. {
  23. l.unloadAndStop();
  24. System.gc();
  25. System.gc();
  26. try {
  27. new LocalConnection().connect('gc');
  28. new LocalConnection().connect('gc');
  29. } catch (e:*) {}
  30. }
  31. else
  32. l.load(new URLRequest("Lighthouse.jpg"), lc);
  33. }

URL: http://simplistika.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.