Posted By

damarev on 01/23/08


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

abdsign
THEPWN3R


loader class


 / Published in: ActionScript 3
 

URL: http://www.cristalab.com/tips/51032/clase-para-cargar-contenido-externo-en-actionscript-3

  1. /*
  2.  
  3. Usage:
  4.  
  5. import com.zguillez.display.Contenedor;
  6.  
  7. var cont:Contenedor = new Contenedor();
  8. cont.asset = "pelicula.swf"
  9.  
  10.  
  11. cont.addEventListener(Contenedor.CARGADO, listo);
  12. function listo(e:Event):void
  13. {
  14.   trace("carga lista")
  15. }
  16. cont.asset = "pelicula2.swf"
  17.  
  18.  
  19. */
  20.  
  21. package com.zguillez.display
  22. {
  23. import flash.display.Sprite;
  24. import flash.display.Loader;
  25. import flash.net.URLRequest;
  26. import flash.events.Event;
  27. import flash.events.EventDispatcher;
  28. //-----------------------------------------
  29. public class Contenedor extends Sprite
  30. {
  31. public static var CARGADO:String = "cargado";
  32. private var _clip:Sprite = new Sprite();
  33. private var _cargado:Boolean = false;
  34. private var _content:Sprite;
  35. private var _urlAsset:String;
  36. //-----------------------------------------
  37. public function Contenedor(asset:String=null)
  38. {
  39. _urlAsset = asset;
  40. if (_urlAsset != null) {
  41. iniLoad();
  42. }
  43. }
  44. //-----------------------------------------
  45. private function iniLoad(asset:String=null):void
  46. {
  47. var loader:Loader = new Loader();
  48. var request:URLRequest = new URLRequest(_urlAsset);
  49. loader.load(request);
  50. var dispatcher:EventDispatcher = loader.contentLoaderInfo;
  51. dispatcher.addEventListener(Event.INIT, registraContenido);
  52. addChild(loader);
  53. }
  54. //-----------------------------------------
  55. public function set asset(a:String):void
  56. {
  57. if (_urlAsset != null) {
  58. removeChild(_clip);
  59. }
  60. _urlAsset = a;
  61. iniLoad();
  62. }
  63. //-----------------------------------------
  64. public function get clip():Sprite
  65. {
  66. return _clip;
  67. }
  68. public function get cargado():Boolean
  69. {
  70. return _cargado;
  71. }
  72. //-----------------------------------------
  73. public function registraContenido(e:Event):void
  74. {
  75. _cargado = true;
  76. _clip = e.target.content;
  77. dispatchEvent(new Event(Contenedor.CARGADO));
  78. }
  79. //-----------------------------------------
  80. }
  81. }

Report this snippet  

You need to login to post a comment.