Multibricks.as

  1. /*
  2.  * Uno de los menús con sus opciones
  3.  *
  4.  *
  5.  * ProInf.net, 2008
  6.  * GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/deed.es
  7.  *
  8.  */
  9. class Multibricks extends Family implements Initiable {
  10.  
  11. //////////////////////////////////////////////////
  12. // Propiedades de la clase
  13.  
  14. private static var counter:Number = 0; // Contador de menús
  15.  
  16. //////////////////////////////////////////////////
  17. // Propiedades del objeto
  18.  
  19. private var idMenu:String = "";
  20. private var xml:XML = null;
  21. private var level:Number = 0;
  22. ////private var title:String = "";
  23.  
  24.  
  25. //////////////////////////////////////////////////
  26. // Constructor
  27.  
  28. public function Multibricks (idMenu:String) {
  29. super( _root.createEmptyMovieClip("menu"+counter, counter++));
  30. this.idMenu = idMenu;
  31. Menus.getInstance().memorize(this);
  32. if (idMenu == "index") {
  33. var profile:Profile = Profile.getInstance();
  34. super.setLocation(profile.getXStartMenu(), profile.getYStartMenu());
  35. relocationToVirtual();
  36. }
  37. }
  38.  
  39. //////////////////////////////////////////////////
  40. // Destructor
  41.  
  42. /** Free resources. Call manually just before delete this class */
  43. public function die() {
  44. ////Console.show("MenuBrick.die " + idMenu);
  45. Animatron.hideMultibricks(this);
  46. Menus.getInstance().unmemorize(this);
  47. super.die();
  48.  
  49. }
  50.  
  51. //////////////////////////////////////////////////
  52. // Getters
  53.  
  54. public function getIdMenu():String { return idMenu; }
  55. public function getXml():XML { return xml; }
  56. public function getLevel():Number { return level; }
  57. ////public function getTitle():String { return title; }
  58.  
  59. //////////////////////////////////////////////////
  60. // Setters
  61.  
  62. private function setLevel(level:Number) {
  63. this.level = level;
  64. }
  65. /*private function setTitle(title:String) {
  66. this.title = title;
  67. }*/
  68.  
  69. //////////////////////////////////////////////////
  70. // Métodos sobreescritos
  71.  
  72. public function setLocation(x:Number, y:Number) {
  73. super.setLocation(x, y);
  74.  
  75. if ((getY() + getHeight()) > Stage.height) {
  76. super.setLocation(x, Math.max(0, Stage.height - getHeight()));
  77. }
  78. relocationToVirtual();
  79. Animatron.showMultibricks(this);
  80. }
  81.  
  82. //////////////////////////////////////////////////
  83. // Inicializador
  84.  
  85. public function initFromBrick(brick:Brick) {
  86. var menuParent:Multibricks = Multibricks(brick.getParent());
  87. setSource(brick);
  88. setLevel(menuParent.getLevel() + 1);
  89.  
  90. init(menuParent.getXml());
  91.  
  92. setLocation(menuParent.getX(), brick.getY() + menuParent.getY()); // Must be after init because calculation menu size
  93.  
  94. //menus.purgeLevels(this);
  95.  
  96. ////getFirstChild().setTitle( getFirstChild().getTitle() + " " + getLevel() );
  97. }
  98.  
  99. public function init(xml:XML) {
  100. //Utils.test();
  101.  
  102. this.xml = xml;
  103.  
  104. var brick:Brick = null;
  105. var index:Number = 1;
  106. var root:XMLNode = xml.firstChild;
  107.  
  108. var link:Link = new Link();
  109. var movierecord:Movierecord = new Movierecord();
  110.  
  111. // Posición para el título. Se inserta luego al final para que tenga el orden-Z mayor posible
  112. addChild(null);
  113.  
  114. if (root.nodeName == "menuxml") {
  115.  
  116. link.getXMLNodeAttributes(root);
  117. movierecord.getXMLNodeAttributes(root);
  118.  
  119. for (var m=0; m<=root.childNodes.length; ++m) {
  120. var menu:XMLNode = root.childNodes[m];
  121. if (menu.nodeName == "menu" && menu.attributes.id == this.idMenu) {
  122.  
  123. link.getXMLNodeAttributes(menu);
  124. movierecord.getXMLNodeAttributes(menu);
  125. getXMLNodeAttributes(menu);
  126.  
  127. for (var e=0; e<menu.childNodes.length; ++e) {
  128. var element:XMLNode = menu.childNodes[e];
  129. if (element.nodeName == "option" || element.nodeName == "separator")
  130. {
  131. brick = new Brick(this); addChild(brick);
  132.  
  133. brick.setLink (link.clone());
  134. brick.setMovierecord (movierecord.clone());
  135. brick.getXMLNodeAttributes (element);
  136.  
  137. brick.setType (element.nodeName);
  138. brick.setIndex (index++);
  139. }
  140. }
  141. break;
  142. }
  143. }
  144. }
  145.  
  146. // BOTTOM BRICK
  147. brick = new Brick(this); addChild(brick);
  148. brick.setType("bottom");
  149. brick.setIndex(index++);
  150. setSize (brick.getWidth(), brick.getY() + brick.getHeight());
  151.  
  152. // TOP BRICK (TITLE MENU)
  153. brick = new Brick(this); setChild(0, brick);
  154. brick.setType("title");
  155. brick.setTitle(getTitle());
  156. brick.setIndex(0);
  157.  
  158. Brick(getChild(1)).showSelect(true);
  159.  
  160. }
  161.  
  162.  
  163. //////////////////////////////////////////////////
  164. // Métodos públicos
  165.  
  166. /*public function close():Boolean {
  167. menus.purgeLevels(this);
  168. return getIdMenu() !== "index";
  169. }*/
  170.  
  171. public function purgeLevels():Void {
  172. Menus.getInstance().purgeLevels(this);
  173. }
  174.  
  175. public function toString():String {
  176. return "Multibricks:"+getIdMenu() + " " + getTitle() + " " + super.toString();
  177. }
  178.  
  179. //////////////////////////////////////////////////
  180. // Métodos propios
  181.  
  182. /*public function getXMLNodeAttributes(node:XMLNode) {
  183. if (node.attributes.title != undefined) { setTitle(node.attributes.title); }
  184. }*/
  185.  
  186. /* // Comprueba si todos los enlaces han sido visitados
  187. public function checkVisited():Boolean {
  188. for (var index:Number = getCountChildren()-1; index >= 0; index--) {
  189. var brick:Brick = Brick(getChild(index));
  190. if (brick.getType() == "option") {
  191. if (brick.isVisited() == false) {
  192. return false;
  193. }
  194. }
  195. }
  196. History.getInstance().add(getIdMenu());
  197. if (getSource() != null) {
  198. Brick(getSource()).refresh();
  199. }
  200. return true;
  201. } */
  202. }
  203.  
  204.  

Proinf.net