Link.as

  1. /**
  2.  * Tratamiento de los enlaces
  3.  *
  4.  * ProInf.net, 2008
  5.  * GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/deed.es
  6.  *
  7.  */
  8. class Link {
  9.  
  10. //////////////////////////////////////////////////
  11. // Propiedades
  12.  
  13. private var link:String = ""; // Enlace
  14. private var base:String = ""; // Base del enlace
  15. private var target:String = ""; // Página web destino o clip destino
  16.  
  17. private var loader:Boolean = true; // Mostrar el progreso de carga
  18.  
  19. //////////////////////////////////////////////////
  20. // Constructor
  21.  
  22. public function Link () {
  23. link = "";
  24. base = "";
  25. target = "target";
  26. }
  27.  
  28. //////////////////////////////////////////////////
  29. // Getters
  30.  
  31. public function getLink():String {
  32. if (link == "") {
  33. return "";
  34. }
  35. else if (
  36. Utils.startsWith(link, "/") ||
  37. Utils.startsWith(link, "..") ||
  38. Utils.startsWith(link, "http://") ||
  39. Utils.startsWith(link, "mailto:"))
  40. {
  41. return link;
  42. }
  43. else {
  44. return base + link;
  45. }
  46. }
  47. public function getBase():String { return base; }
  48. public function getTarget():String { return target; }
  49.  
  50. public function isVisited():Boolean { return History.getInstance().contains(getLink()); }
  51. public function isLoader():Boolean { return loader; }
  52.  
  53. public function getType():String { // SWF, URL
  54. if (
  55. Utils.endsWith(link, ".swf") ||
  56. Utils.contains(link, ".swf?") ||
  57. Utils.endsWith(link, ".jpg"))
  58. {
  59. return "SWF";
  60. }
  61. else if (Utils.endsWith(link, ".xml")) {
  62. return "XML";
  63. }
  64. else {
  65. return "URL";
  66. }
  67. }
  68.  
  69. //////////////////////////////////////////////////
  70. // Setters
  71.  
  72. public function setLink(link:String) {
  73. this.link = Utils.clearUndefined(link, "");
  74. }
  75. public function setBase(base:String) {
  76. this.base = Utils.clearUndefined(base, "");
  77. }
  78. public function setTarget(target:String) {
  79. this.target = Utils.clearUndefined(target, "");
  80. }
  81. public function setVisited(visited:Boolean) {
  82. if (visited) History.getInstance().add(getLink());
  83. else History.getInstance().remove(getLink());
  84. }
  85. public function setLoaderFromString(on_off:String) {
  86. this.loader = Utils.clearUndefined(on_off, "off") == "on";
  87. }
  88.  
  89. //////////////////////////////////////////////////
  90. // Métodos públicos
  91.  
  92. public function clone():Link {
  93. var clon:Link = new Link();
  94. clon.link = this.link;
  95. clon.base = this.base;
  96. clon.target = this.target;
  97. clon.loader = this.loader;
  98. return clon;
  99. }
  100.  
  101. public function getXMLNodeAttributes(node:XMLNode) {
  102. if (node.attributes.link != undefined) { setLink(node.attributes.link); }
  103. if (node.attributes.base != undefined) { setBase(node.attributes.base); }
  104. if (node.attributes.target != undefined) { setTarget(node.attributes.target); }
  105. if (node.attributes.loader != undefined) { setLoaderFromString(node.attributes.loader); }
  106. }
  107.  
  108. public function doLink ():Boolean {
  109. if (getLink() == "") {
  110. return false;
  111. }
  112. else {
  113. setVisited(true);
  114.  
  115. if (getType() == "SWF") {
  116. if (isLoader()) {
  117. Reloader.getInstance().init(getLink());
  118. }
  119. else {
  120. Container.getInstance().setTarget(this);
  121. }
  122. }
  123. else if (getType() == "XML") {
  124. // ...
  125. // ...PENDIENTE...
  126. // ...
  127. }
  128. else {
  129. getURL(getLink(), target);
  130. }
  131. return true;
  132. }
  133. }
  134.  
  135. public function toString():String {
  136. return "Link="+getLink() + (isVisited()?"*":"");
  137. }
  138.  
  139. //////////////////////////////////////////////////
  140. // Métodos internos
  141.  
  142. }

Proinf.net