Menu.as 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package elements.menu {
  2. import flash.display.Sprite;
  3. import flash.events.MouseEvent;
  4. import elements.menu.menuItem;
  5. import caurina.transitions.Tweener;
  6. import caurina.transitions.Equations;
  7. import string.Utils;
  8. import flash.filters.DropShadowFilter;
  9. public class Menu extends Sprite {
  10. private var original_alpha:Number;
  11. private var props:Properties;
  12. private var first_showing:Boolean;
  13. private var hidden_pos:Number;
  14. public function Menu( chartID:String, json:Object ) {
  15. this.props = new DefaultMenuProperties(json);
  16. this.original_alpha = 0.4;
  17. this.alpha = 1;
  18. var pos:Number = 5;
  19. var height:Number = 0;
  20. this.first_showing = true;
  21. for each ( var val:Object in json.values )
  22. {
  23. var tmp:DefaultCameraIconProperties = new DefaultCameraIconProperties(val);
  24. var menu_item:menuItem = menu_item_factory.make(chartID, tmp);
  25. menu_item.x = 5;
  26. menu_item.y = pos;
  27. this.addChild(menu_item);
  28. height = menu_item.y + menu_item.height + 5;
  29. pos += menu_item.height + 5;
  30. }
  31. var width:Number = 0;
  32. for ( var i:Number = 0; i < this.numChildren; i++ )
  33. width = Math.max( width, this.getChildAt(i).width );
  34. this.draw(width+10, height);
  35. this.hidden_pos = height;
  36. /*
  37. var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
  38. dropShadow.blurX = 4;
  39. dropShadow.blurY = 4;
  40. dropShadow.distance = 4;
  41. dropShadow.angle = 45;
  42. dropShadow.quality = 2;
  43. dropShadow.alpha = 0.5;
  44. // apply shadow filter
  45. this.filters = [dropShadow];
  46. */
  47. this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
  48. this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
  49. }
  50. private function draw(width:Number, height:Number): void {
  51. this.graphics.clear();
  52. var colour:Number = string.Utils.get_colour( this.props.get('colour') );
  53. var o_colour:Number = string.Utils.get_colour( this.props.get('outline-colour') );
  54. this.graphics.lineStyle( 1, o_colour );
  55. this.graphics.beginFill(colour, 1);
  56. this.graphics.moveTo( 0, -2 );
  57. this.graphics.lineTo( 0, height );
  58. this.graphics.lineTo( width-25, height );
  59. this.graphics.lineTo( width-20, height+10 );
  60. this.graphics.lineTo( width, height+10 );
  61. this.graphics.lineTo( width, -2 );
  62. this.graphics.endFill();
  63. // arrows
  64. this.graphics.lineStyle( 1, o_colour );
  65. this.graphics.moveTo( width-15, height+3 );
  66. this.graphics.lineTo( width-10, height+8 );
  67. this.graphics.lineTo( width-5, height+3 );
  68. this.graphics.moveTo( width-15, height );
  69. this.graphics.lineTo( width-10, height+5 );
  70. this.graphics.lineTo( width-5, height );
  71. }
  72. public function mouseOverHandler(event:MouseEvent):void {
  73. Tweener.removeTweens(this);
  74. Tweener.addTween(this, { y:0, time:0.4, transition:Equations.easeOutBounce } );
  75. Tweener.addTween(this, { alpha:1, time:0.4, transition:Equations.easeOutBounce } );
  76. }
  77. public function mouseOutHandler(event:MouseEvent):void {
  78. this.hide_menu();
  79. }
  80. private function hide_menu(): void
  81. {
  82. Tweener.removeTweens(this);
  83. Tweener.addTween(this, { y:-this.hidden_pos, time:0.4, transition:Equations.easeOutBounce } );
  84. Tweener.addTween(this, { alpha:this.original_alpha, time:0.4, transition:Equations.easeOutBounce } );
  85. }
  86. public function resize(): void {
  87. if ( this.first_showing ) {
  88. this.y = 0;
  89. this.first_showing = false;
  90. Tweener.removeTweens(this);
  91. Tweener.addTween(this, { time:3, onComplete:this.hide_menu } );
  92. }
  93. else {
  94. this.y = -(this.height) + 10;
  95. }
  96. this.x = this.stage.stageWidth - this.width - 5;
  97. }
  98. }
  99. }