Container.as

  1. /**
  2.  * Encapsula el clip contenedor.
  3.  * Su misiónn es mostrar la película o foto que se carga.
  4.  *
  5.  * ProInf.net, 2008
  6.  * GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/deed.es
  7.  *
  8.  */
  9. class Container {
  10.  
  11. //////////////////////////////////////////////////
  12. // Propiedades de la clase
  13.  
  14. private static var WIDTH_CORNER:Number = 25;
  15. private static var HEIGHT_CORNER:Number = 25;
  16.  
  17. private static var container:Container = null;
  18.  
  19. //////////////////////////////////////////////////
  20. // Propiedades del objeto
  21.  
  22. private var mc_container:MovieClip; // Contenedor en la escena
  23. private var mc_target:MovieClip; // Donde se visualiza la película
  24. private var mc_mask:MovieClip; // Máscara para no salirse de los límites
  25. private var mc_background:MovieClip; // Para indicar un color de fondo
  26. private var mc_limits:MovieClip; // Límites máximos que se pueden alcanzar
  27. private var mc_northwest:MovieClip; // Esquina superior derecha
  28. private var mc_north:MovieClip; // Lado superior
  29. private var mc_northeast:MovieClip; // Esquina superior izquierda
  30. private var mc_west:MovieClip; // Lado izquierdo
  31. private var mc_east:MovieClip; // Lado derecho
  32. private var mc_southwest:MovieClip; // Esquina inferior izquierda
  33. private var mc_south:MovieClip; // Lado inferior
  34. private var mc_southeast:MovieClip; // Esquina inferior derecha
  35. private var mc_percent:MovieClip; // Porcentaje de carga y barra de progreso
  36. private var mc_buttons:MovieClip; // Botones de restaurar, maximizar y cerrar
  37.  
  38. private var backgroundColor:Color = null;
  39. private var movierecord:Movierecord = null; // Título, color, ancho y alto
  40. private var fullSize:Boolean = false;
  41. private var animated:Boolean = false;
  42. private var xContainer:Number;
  43. private var yContainer:Number;
  44.  
  45. //////////////////////////////////////////////////
  46. // Constructor
  47.  
  48. private function Container () {
  49. mc_container = _root["container"];
  50. mc_target = mc_container["target"];
  51. mc_mask = mc_container["mask"];
  52. mc_background = mc_container["background"];
  53. mc_limits = mc_container["limits"];
  54. mc_northwest = mc_container["northwest"];
  55. mc_north = mc_container["north"];
  56. mc_northeast = mc_container["northeast"];
  57. mc_west = mc_container["west"];
  58. mc_east = mc_container["east"];
  59. mc_southwest = mc_container["southwest"];
  60. mc_south = mc_container["south"];
  61. mc_southeast = mc_container["southeast"];
  62. mc_percent = mc_container["percent"];
  63. mc_buttons = mc_container["buttons"];
  64.  
  65. backgroundColor = new Color(mc_background);
  66. movierecord = new Movierecord();
  67.  
  68. xContainer = mc_container._x;
  69. yContainer = mc_container._y;
  70.  
  71. /////Console.show("Container " + anchoMaximo + "x" + altoMaximo);
  72. }
  73.  
  74.  
  75. public static function getInstance():Container {
  76. if (container == null) {
  77. container = new Container();
  78. }
  79. return container;
  80. }
  81.  
  82. //////////////////////////////////////////////////
  83. // Destructor
  84.  
  85. /** Free resources. Call manually just before delete this class */
  86. public function die() {
  87. }
  88.  
  89. //////////////////////////////////////////////////
  90. // Getters
  91.  
  92. public function getTarget():MovieClip { return mc_target; }
  93. public function getMovierecord():Movierecord { return movierecord; }
  94. private function getAnimated():Boolean { return animated; }
  95. private function getFullSize():Boolean { return fullSize; }
  96.  
  97. //////////////////////////////////////////////////
  98. // Setters
  99.  
  100. public function setTarget(link:Link) {
  101. getTarget().loadMovie(link.getLink());
  102. showTarget();
  103. }
  104. public function setMovierecord(mr:Movierecord) {
  105. this.movierecord = mr;
  106. }
  107. private function setAnimated(animated:Boolean) {
  108. this.animated = animated;
  109. }
  110. private function setFullSize(valor:Boolean) {
  111. this.fullSize = valor;
  112. Menus.getInstance().setVisible(!valor);
  113. }
  114.  
  115. //////////////////////////////////////////////////
  116. // Interfaz
  117.  
  118. public function hidePerCent() {
  119. setFullSize(false);
  120. setAnimated(false);
  121. setSize(10, 10, 1.0);
  122. mc_percent._visible = false;
  123. mc_target._visible = false;
  124. mc_buttons._visible = false;
  125. mc_container.title = "";
  126. setBackground(null);
  127.  
  128. }
  129. public function showPerCent(percent:Number) {
  130. //Console.show("showPerCent " + mc_percent._width + "x"+ mc_percent._height);
  131. mc_percent.gotoAndStop(normalizeFrame(percent));
  132. mc_percent.percent = percent;
  133. setFullSize(false);
  134. setAnimated(false);
  135. setSize(100, 25, 1.0);
  136. mc_percent._visible = true;
  137. mc_target._visible = false;
  138. mc_buttons._visible = false;
  139. mc_container.title = "Cargando..."; // '" + movierecord.getTitle() + "' ...";
  140. setBackground(null);
  141. }
  142. public function showTarget() {
  143. setAnimated(true);
  144. setSize(getTargetWidth(), getTargetHeight(), getTargetRatio(), true);
  145. mc_percent._visible = false;
  146. mc_target._visible = true;
  147. mc_buttons._visible = true;
  148. mc_container.title = movierecord.getTitle() ; // movierecord.toString();
  149. setBackground(movierecord.getColor());
  150. }
  151. public function showError() {
  152. // ...
  153. // ...PENDIENTE...
  154. // ...
  155. }
  156.  
  157. public function doClose() {
  158. setFullSize(false);
  159. setAnimated(true);
  160. setSize(100, 1, 1.0);
  161. mc_percent._visible = false;
  162. mc_target._visible = false;
  163. mc_container.title = "";
  164. setBackground(null);
  165. }
  166. public function doMaximize() {
  167. setFullSize(true);
  168. showTarget();
  169. }
  170. public function doRestore() {
  171. setFullSize(false);
  172. showTarget();
  173. }
  174.  
  175. //////////////////////////////////////////////////
  176. // Métodos internos
  177.  
  178. private function setBackground(rgb:Number) {
  179. if (rgb == undefined || rgb == null) {
  180. backgroundColor.setRGB( Profile.getInstance().getDefaultTargetColor() );
  181. }
  182. else {
  183. backgroundColor.setRGB(rgb);
  184. }
  185. }
  186.  
  187. private function normalizeFrame(percent:Number):Number {
  188. var fotograma:Number = int(percent);
  189. if (fotograma < 1) fotograma = 1;
  190. else if (fotograma > 100) fotograma = 100;
  191. return fotograma;
  192. }
  193.  
  194. private function getTargetWidth() {
  195. if (movierecord.getWidth() > 0) return movierecord.getWidth();
  196. else if (mc_target._width > 0) return mc_target._width;
  197. else return Profile.getInstance().getDefaultTargetWidth();
  198. }
  199. private function getTargetHeight() {
  200. if (movierecord.getHeight() > 0) return movierecord.getHeight();
  201. if (mc_target._height > 0) return mc_target._height;
  202. else return Profile.getInstance().getDefaultTargetHeight();
  203. }
  204.  
  205. private function getTargetRatio():Number {
  206. var scale:String = movierecord.getScale()
  207. if (scale == "off" || scale == "noscale") {
  208. return 1;
  209. }
  210. else { // if (scale == "on" || scale = "scale")
  211. var anchoMaximo:Number = 0;
  212. var altoMaximo:Number = 0;
  213. if (getFullSize()) {
  214. anchoMaximo = Stage.width;
  215. altoMaximo = Stage.height;
  216. }
  217. else {
  218. anchoMaximo = mc_limits._width;
  219. altoMaximo = mc_limits._height;
  220. }
  221. anchoMaximo -= WIDTH_CORNER*2;
  222. altoMaximo -= HEIGHT_CORNER*2;
  223.  
  224. return Math.min( anchoMaximo/getTargetWidth(), altoMaximo/getTargetHeight() );
  225. }
  226. }
  227.  
  228. private function setSize(ancho:Number, alto:Number, ratio:Number) {
  229. ancho *= ratio;
  230. alto *= ratio;
  231.  
  232. mc_target._xscale = 100*ratio;
  233. mc_target._yscale = 100*ratio;
  234.  
  235. setX(mc_container, getFullSize()? 0: xContainer);
  236. setY(mc_container, getFullSize()? 0: yContainer);
  237.  
  238. setWidth(mc_mask, ancho);
  239. setWidth(mc_background, ancho);
  240. setHeight(mc_mask, alto);
  241. setHeight(mc_background, alto);
  242.  
  243. setWidth(mc_north, ancho);
  244. setWidth(mc_south, ancho);
  245. setHeight(mc_west, alto);
  246. setHeight(mc_east, alto);
  247.  
  248. setX(mc_northeast, WIDTH_CORNER+ancho);
  249. setX(mc_southeast, WIDTH_CORNER+ancho);
  250. setX(mc_east, WIDTH_CORNER+ancho);
  251.  
  252. setY(mc_southwest, HEIGHT_CORNER+alto);
  253. setY(mc_southeast, HEIGHT_CORNER+alto);
  254. setY(mc_south, HEIGHT_CORNER+alto);
  255.  
  256. setX(mc_buttons, WIDTH_CORNER+ancho);
  257. }
  258.  
  259. private function setWidth(mc:MovieClip, valor:Number) {
  260. if (getAnimated()) Animatron.showContainerElement(mc, "_width", valor);
  261. else mc._width = valor;
  262. }
  263. private function setHeight(mc:MovieClip, valor:Number) {
  264. if (getAnimated()) Animatron.showContainerElement(mc, "_height", valor);
  265. else mc._height = valor;
  266. }
  267. private function setX(mc:MovieClip, valor:Number) {
  268. if (getAnimated()) Animatron.showContainerElement(mc, "_x", valor);
  269. else mc._x = valor;
  270. }
  271. private function setY(mc:MovieClip, valor:Number) {
  272. if (getAnimated()) Animatron.showContainerElement(mc, "_y", valor);
  273. else mc._y = valor;
  274. }
  275.  
  276. }
  277.  

Proinf.net