Family.as

  1. /**
  2.  * Relaciones de parentesco de hijos y padres
  3.  *
  4.  * ProInf.net, 2008
  5.  * GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/deed.es
  6.  *
  7.  */
  8. class Family extends Clip {
  9.  
  10. //////////////////////////////////////////////////
  11. // Propiedades
  12.  
  13. private var clipParent:Family = null;
  14. private var children:Array = null;
  15.  
  16. //////////////////////////////////////////////////
  17. // Constructor
  18.  
  19. public function Family (movieClip:MovieClip) {
  20. super(movieClip);
  21. children = new Array();
  22. }
  23.  
  24. //////////////////////////////////////////////////
  25. // Destructor
  26.  
  27. /** Free resources. Call manually just before delete this class */
  28. public function die() {
  29. while (children.length > 0) {
  30. var child:Family = Family(children.pop());
  31. child.die(); delete child;
  32. }
  33. delete children;
  34. super.die();
  35. }
  36.  
  37. //////////////////////////////////////////////////
  38. // Getters
  39.  
  40. public function getParent():Family { return clipParent; }
  41. public function getCountChildren():Number { return children.length };
  42. public function getChild(index:Number):Family {
  43. if (index < children.length) {
  44. return Family(children[index]);
  45. }
  46. return null;
  47. }
  48. public function getFirstChild():Family { return getChild(0); }
  49. public function getLastChild():Family { return getChild(children.length); }
  50.  
  51.  
  52. //////////////////////////////////////////////////
  53. // Setters
  54.  
  55. public function setParent(parent:Family) {
  56. this.clipParent = parent;
  57. }
  58. public function addChild(child:Family) {
  59. children.push(child);
  60. child.setParent(this);
  61. }
  62. public function setChild(index:Number, child:Family) {
  63. children[index] = child;
  64. child.setParent(this);
  65. }
  66.  
  67.  
  68. //////////////////////////////////////////////////
  69. // Métodos públicos
  70.  
  71. public function toString():String {
  72. return "Family:"+getCountChildren() + "," + super.toString();
  73. }
  74.  
  75. //////////////////////////////////////////////////
  76. // Métodos propios
  77.  
  78. }

Proinf.net