Clip.as

  1. /**
  2.  * Encapsula un MovieClip
  3.  * Tiene un título, posición y tamaño.
  4.  * Establece dependencias entre origen y destino
  5.  *
  6.  * ProInf.net, 2008
  7.  * GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/deed.es
  8.  *
  9.  */
  10. class Clip {
  11.  
  12. //////////////////////////////////////////////////
  13. // Propiedades
  14.  
  15. private var movieClip:MovieClip = null;
  16. private var title:String = "";
  17. private var x:Number = 0;
  18. private var y:Number = 0;
  19. private var width:Number = 0;
  20. private var height:Number = 0;
  21.  
  22. private var clipSource:Clip = null;
  23. private var clipTarget:Clip = null;
  24.  
  25. //////////////////////////////////////////////////
  26. // Constructor
  27.  
  28. public function Clip (movieClip:MovieClip) {
  29. setMovieClip(movieClip);
  30. }
  31.  
  32. //////////////////////////////////////////////////
  33. // Destructor
  34.  
  35. /** Free resources. Call manually just before delete this class */
  36. public function die() {
  37. ///////movieClip.removeMovieClip();
  38. if (clipSource != null) clipSource.clipTarget = null;
  39. if (clipTarget != null) clipTarget.clipSource = null;
  40. }
  41.  
  42. //////////////////////////////////////////////////
  43. // Getters
  44.  
  45. public function getMovieClip():MovieClip { return movieClip; }
  46. public function getTitle():String { return title; }
  47. public function getSource():Clip { return clipSource; }
  48. public function getTarget():Clip { return clipTarget; }
  49.  
  50. public function getX():Number { return x; }
  51. public function getY():Number { return y; }
  52. public function getWidth():Number { return width; }
  53. public function getHeight():Number { return height; }
  54.  
  55. //////////////////////////////////////////////////
  56. // Setters
  57.  
  58. public function setMovieClip(movieClip:MovieClip) {
  59. this.movieClip = movieClip;
  60. }
  61. public function setTitle(title:String) {
  62. this.title = Utils.clearUndefined(title, "");
  63. movieClip.title = this.title;
  64. }
  65. public function setSource(clip:Clip) {
  66. this.clipSource = clip;
  67. clip.clipTarget = this;
  68. }
  69. public function setTarget(clip:Clip) {
  70. this.clipTarget = clip;
  71. clip.clipSource = this;
  72. }
  73.  
  74. public function setLocation(x:Number, y:Number) {
  75. if (x != null) { this.x = x; }
  76. if (y != null) { this.y = y; }
  77. }
  78. public function setSize(width:Number, height:Number) {
  79. if (x != null) {
  80. this.width = width;
  81. }
  82. if (y != null) {
  83. this.height = height;
  84. }
  85. }
  86. public function setVisible(valor:Boolean) {
  87. movieClip._visible = valor;
  88. }
  89.  
  90. //////////////////////////////////////////////////
  91. // Métodos públicos
  92.  
  93. public function getXMLNodeAttributes(node:XMLNode) {
  94. if (node.attributes.title != undefined) { setTitle(node.attributes.title); }
  95. }
  96.  
  97. public function relocationToVirtual() {
  98. movieClip._x = x;
  99. movieClip._y = y;
  100. }
  101. public function relocationToReal() {
  102. x = movieClip._x;
  103. y = movieClip._y;
  104. }
  105.  
  106. /*public function removeSource(clip:Clip) {
  107. this.clipSource = null;
  108. clip.clipTarget = null;
  109. }
  110. public function removeTarget(clip:Clip) {
  111. this.clipTarget = null;
  112. clip.clipSource = null;
  113. }*/
  114.  
  115.  
  116. public function toString():String {
  117. //var cs:String = ""; if (clipSource != null) cs = ",cs:"+clipSource.getTitle();
  118. //var ct:String = ""; if (clipTarget != null) ct = ",ct:"+clipTarget.getTitle();
  119. return "Clip="+getTitle();
  120. }
  121. //////////////////////////////////////////////////
  122. // Métodos propios
  123.  
  124.  
  125. }

Proinf.net