source: code/Website/open-flash-chart/elements/menu/menuItem.as

Last change on this file was 7849, checked in by dennisw, 15 years ago
File size: 3.1 KB
Line 
1package elements.menu {
2
3 import flash.display.Sprite;
4 import flash.events.MouseEvent;
5 import flash.external.ExternalInterface;
6 import flash.text.TextField;
7 import flash.text.TextFieldType;
8 import flash.text.TextFormat;
9 import flash.filters.GlowFilter;
10 import string.Utils;
11
12 public class menuItem extends Sprite {
13
14 protected var chartId:String;
15 protected var props:Properties;
16
17 public function menuItem(chartId:String, props:Properties) {
18
19 this.props = props;
20
21 this.buttonMode = true;
22 this.useHandCursor = true;
23 this.chartId = chartId;
24
25 this.alpha = 0.5;
26
27 var width:Number = this.add_elements();
28
29 this.draw_bg(
30 width +
31 10 // 5px padding on either side
32 );
33
34 this.addEventListener(MouseEvent.CLICK, mouseClickHandler);
35 this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
36 this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
37 this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
38 }
39
40 protected function add_elements(): Number {
41 var width:Number = this.add_text(this.props.get('text'), 5);
42 return width;
43 }
44
45 private function draw_bg( width:Number ):void {
46 this.graphics.beginFill(string.Utils.get_colour( this.props.get('background-colour') ));
47 this.graphics.drawRoundRect(0, 0, width, 20, 5, 5 );
48 this.graphics.endFill();
49 }
50
51
52 protected function add_text(text:String, left:Number): Number {
53 var title:TextField = new TextField();
54 title.x = left;
55 title.y = 0;
56
57 //this.text = 'Save chart';
58
59 title.htmlText = text;
60
61 var fmt:TextFormat = new TextFormat();
62 fmt.color = string.Utils.get_colour( this.props.get('text-colour') );
63 fmt.font = 'Verdana';
64// fmt.bold = this.css.font_weight == 'bold'?true:false;
65 fmt.size = 10;// this.css.font_size;
66 fmt.underline = true;
67// fmt.align = "center";
68
69 title.setTextFormat(fmt);
70 title.autoSize = "left";
71
72 // so we don't get an I-beam cursor when we mouse
73 // over the text - pass mouse messages onto the button
74 title.mouseEnabled = false;
75
76// title.border = true;
77
78 this.addChild(title);
79
80 return title.width;
81 }
82
83 public function mouseClickHandler(event:MouseEvent):void {
84 this.alpha = 0.0;
85 tr.aces('Menu item clicked:', this.props.get('javascript-function')+'('+this.chartId+')');
86 ExternalInterface.call(this.props.get('javascript-function'), this.chartId);
87 this.alpha = 1.0;
88 }
89
90 public function mouseOverHandler(event:MouseEvent):void {
91 this.alpha = 1;
92
93 ///Glow Filter
94 var glow:GlowFilter = new GlowFilter();
95 glow.color = string.Utils.get_colour( this.props.get('glow-colour') );
96 glow.alpha = 0.8;
97 glow.blurX = 4;
98 glow.blurY = 4;
99 glow.inner = false;
100
101 this.filters = new Array(glow);
102 }
103
104 public function mouseDownHandler(event:MouseEvent):void {
105 this.alpha = 1.0;
106 }
107
108 public function mouseOutHandler(event:MouseEvent):void {
109 this.alpha = 0.5;
110 this.filters = new Array();
111 }
112 }
113}
Note: See TracBrowser for help on using the repository browser.