Brick.as

  1. /**
  2.  * Uno de los elementos del menú: título, opción, separador o parte inferior.
  3.  *
  4.  * ProInf.net, 2008
  5.  * GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/deed.es
  6.  *
  7.  */
  8. class Brick extends Family {
  9.  
  10. //////////////////////////////////////////////////
  11. // Propiedades de la clase
  12.  
  13. ///private static var BRICK_HEIGHT:Number = 25;
  14. ///private static var BRICK_WIDTH:Number = 250;
  15. private static var counter = 0;
  16.  
  17. private static var currentBrick:Brick = null;
  18.  
  19. //////////////////////////////////////////////////
  20. // Propiedades del objeto
  21.  
  22. private var type:String; // Tipo: option, title, bottom
  23. private var idMenu:String = ""; // Identificador del menú que abre
  24. private var index:Number = -1; // Posición en la lista
  25.  
  26. private var link:Link = null; // Enlace que abre
  27. private var movierecord:Movierecord = null; // Datos visuales
  28.  
  29.  
  30. //////////////////////////////////////////////////
  31. // Constructores
  32.  
  33. public function Brick (parent:Family) {
  34. super (parent.getMovieClip().attachMovie("brick", "brick"+counter, counter++));
  35. this.link = new Link();
  36. this.movierecord = new Movierecord();
  37. setParent(parent);
  38. //setSource(parent);
  39. setTitle("");
  40. }
  41.  
  42. //////////////////////////////////////////////////
  43. // Destructor
  44.  
  45. /** Free resources. Call manually just before delete this class */
  46. public function die() {
  47. ////var top:Clip = Multibricks(getParent()).getFirstChild();
  48. ////setLocation(top.getX(), top.getY());
  49. Animatron.hideBrick(this); //getMovieClip().removeMovieClip();
  50. super.die();
  51. }
  52.  
  53. //////////////////////////////////////////////////
  54. // Getters
  55.  
  56. public function getType():String { return type; }
  57. public function getIdMenu():String { return idMenu; }
  58. public function getIndex():Number { return index; }
  59. public function getWidth():Number { return Profile.getInstance().getBrickWidth(); } ///return BRICK_WIDTH;
  60. public function getHeight():Number { return Profile.getInstance().getBrickHeight(); } ///return BRICK_HEIGHT;
  61. public function getLink():Link { return link; }
  62. public function getMovierecord():Movierecord { return movierecord; }
  63. public function isVisited():Boolean {
  64. return History.getInstance().contains(getLink().getLink()) ||
  65. History.getInstance().contains(getIdMenu());
  66. }
  67.  
  68. /*public function getTrueY():Number {
  69. var y:Number = getY();
  70. var source:Family = this;
  71. while (source != null) {
  72. var parent:Clip = Clip(source.getParent());
  73. source = Family(parent.getSource());
  74. y += parent.getY();
  75. }
  76. return y;
  77. }*/
  78.  
  79.  
  80. //////////////////////////////////////////////////
  81. // Setters
  82.  
  83. public function setType (type:String) { // "option", "title", another
  84. this.type = type;
  85. showFrame(type);
  86. makeEvents();
  87. }
  88. public function setIdMenu(id) {
  89. this.idMenu = Utils.clearUndefined(id, "");
  90. if (this.idMenu != "") { setTitle(getTitle() + " »"); }
  91. }
  92. public function setIndex(index:Number) {
  93. this.index = index;
  94. setLocation (0, index*getHeight());
  95. }
  96. public function setMovierecord(mr:Movierecord) {
  97. this.movierecord = mr;
  98. }
  99. public function setLink(link:Link) {
  100. this.link = link;
  101. }
  102.  
  103. //////////////////////////////////////////////////
  104. // Métodos sobreescritos
  105.  
  106. /*public function setTitle(title:String) {
  107. super.setTitle(title);
  108. movierecord.setTitle(title);
  109. }*/
  110.  
  111. public function setLocation(x:Number, y:Number) {
  112. super.setLocation(x,y);
  113. Animatron.showBrick(this); //// relocationToVirtual();
  114. }
  115.  
  116. //////////////////////////////////////////////////
  117. // Métodos públicos
  118.  
  119. public function getXMLNodeAttributes(node:XMLNode) {
  120. super.getXMLNodeAttributes(node);
  121. if (node.attributes.menu != undefined) { setIdMenu(node.attributes.menu); }
  122. link.getXMLNodeAttributes(node);
  123. movierecord.getXMLNodeAttributes(node);
  124. }
  125.  
  126. public function doCurrent() {
  127. if (currentBrick != null) currentBrick.getMovieClip().current.gotoAndStop("no");
  128. getMovieClip().current.gotoAndStop("yes");
  129. currentBrick = this;
  130. }
  131.  
  132. public function doLink():Boolean {
  133. Container.getInstance().setMovierecord(movierecord);
  134. if (getLink().doLink()) {
  135. var menuParent:Multibricks = Multibricks(getParent());
  136. menuParent.purgeLevels();
  137. ////menuParent.checkVisited();
  138. return true;
  139. }
  140. else {
  141. return false;
  142. }
  143. }
  144.  
  145. public function doMenu():Boolean {
  146. if (getIdMenu() != "" && getTarget() == null) {
  147. var menuPopup:Multibricks = new Multibricks(getIdMenu());
  148. menuPopup.initFromBrick(this);
  149. menuPopup.purgeLevels();
  150. History.getInstance().add(getIdMenu()); ////Multibricks(getParent()).checkVisited();
  151. ////Brick(menuPopup.getChild(1)).showSelect(true);
  152. return true;
  153. }
  154. else {
  155. return false;
  156. }
  157. }
  158. public function showSelect(valor:Boolean) {
  159. /*var selected:Selected = Selected.getInstance();
  160. if (valor) {
  161. selected.setVisible(true);
  162. selected.setLocation(0, getY() + getParent().getY());
  163. }
  164. else {
  165. selected.setVisible(false);
  166. }*/
  167. }
  168.  
  169. public function closeMenu():Void {
  170. var menuParent:Multibricks = Multibricks(getParent());
  171. menuParent.purgeLevels();
  172. if (menuParent.getIdMenu() !== "index") {
  173. menuParent.die(); delete menuParent;
  174. }
  175. }
  176.  
  177. public function makeEvents ():Void {
  178. if (type == "option") {
  179. makeOptionEvents(getMovieClip().center);
  180. makeBoxEvents(getMovieClip().left);
  181. makeBoxEvents(getMovieClip().right);
  182. }
  183. else if (type == "title") {
  184. makeTitleEvents(getMovieClip());
  185. }
  186. else {
  187. makeBoxEvents(getMovieClip(), getMovieClip()._parent);
  188. }
  189. }
  190.  
  191. public function removeEvents (mc:MovieClip):Void {
  192. mc.onPress = null;
  193. mc.onRelease = null;
  194. mc.onRollOver = null;
  195. mc.onRollOut = null;
  196. mc.onReleaseOutside = null;
  197. }
  198.  
  199.  
  200. public function refresh () {
  201. showFrame(getType());
  202. }
  203.  
  204. //////////////////////////////////////////////////
  205. // Métodos propios
  206.  
  207. private function showFrame(frameLabel:String) {
  208. /*if (frameLabel == undefined || frameLabel == null) {
  209. frameLabel = getType();
  210. }*/
  211. if (frameLabel == "option" && isVisited()) {
  212. frameLabel = "option_visited";
  213. }
  214. getMovieClip().gotoAndStop(frameLabel);
  215. }
  216.  
  217. private function makeOptionEvents (mc:MovieClip):Void {
  218. var brick:Brick = this;
  219.  
  220. mc.onPress = function () {
  221. brick.showFrame("option_active");
  222. }
  223. mc.onRelease = function () {
  224. this.gotoAndStop("option_selected");
  225. brick.doLink();
  226. brick.doMenu();
  227. brick.doCurrent();
  228. }
  229. mc.onRollOver = function () {
  230. brick.showFrame("option_selected");
  231. brick.showSelect(true);
  232. }
  233. mc.onRollOut = function () {
  234. brick.showFrame("option");
  235. brick.showSelect(false);
  236. }
  237. mc.onReleaseOutside = function () {
  238. brick.showFrame("option");
  239. }
  240. }
  241.  
  242. private function makeTitleEvents (mc:MovieClip):Void {
  243. var brick:Brick = this;
  244. var menuParent:Multibricks = Multibricks(getParent());
  245. mc.onRelease = function () {
  246. brick.closeMenu();
  247. }
  248. }
  249.  
  250. private function makeBoxEvents (mc:MovieClip):Void {
  251. var brick:Brick = this;
  252. var menuParent:Multibricks = Multibricks(getParent());
  253. mc.onRelease = function() {
  254. stopDrag(); //menuParent.setLocation(_parent._x, _parent._y); //2008-06-21
  255. menuParent.relocationToReal();
  256. }
  257. mc.onReleaseOutside = function() {
  258. stopDrag();
  259. menuParent.relocationToReal(); //menuParent.relocationToVirtual();
  260. }
  261. mc.onPress = function() {
  262. var x:Number = Profile.getInstance().getXStartMenu();
  263. menuParent.getMovieClip().startDrag(false, x,0,x,1000);
  264. }
  265. }
  266.  
  267. //////////////////////////////////////////////////
  268. // Métodos sobreescritos
  269.  
  270. public function toString():String {
  271. return "Brick:"+getIndex() + "," + super.toString();
  272. }
  273.  
  274.  
  275. }

Proinf.net