1 | /* */
|
---|
2 |
|
---|
3 | package elements.labels {
|
---|
4 |
|
---|
5 | import flash.display.Sprite;
|
---|
6 | import flash.display.Stage;
|
---|
7 | import flash.text.TextField;
|
---|
8 | import flash.text.TextFieldType;
|
---|
9 | import flash.text.TextFormat;
|
---|
10 | import flash.text.StyleSheet;
|
---|
11 | import flash.events.Event;
|
---|
12 | import flash.text.TextFieldAutoSize;
|
---|
13 | import string.Css;
|
---|
14 | import string.Utils;
|
---|
15 |
|
---|
16 | public class Title extends BaseLabel {
|
---|
17 | public var colour:Number;
|
---|
18 | public var size:Number;
|
---|
19 | private var top_padding:Number = 0;
|
---|
20 |
|
---|
21 | public function Title( json:Object )
|
---|
22 | {
|
---|
23 | super();
|
---|
24 |
|
---|
25 | if( !json )
|
---|
26 | return;
|
---|
27 |
|
---|
28 | // defaults:
|
---|
29 | this.style = "font-size: 12px";
|
---|
30 |
|
---|
31 | object_helper.merge_2( json, this );
|
---|
32 |
|
---|
33 | this.css = new Css( this.style );
|
---|
34 | this.build( this.text );
|
---|
35 | }
|
---|
36 |
|
---|
37 | public function resize():void {
|
---|
38 | if( this.text == null )
|
---|
39 | return;
|
---|
40 |
|
---|
41 | this.getChildAt(0).width = this.stage.stageWidth;
|
---|
42 |
|
---|
43 |
|
---|
44 | //
|
---|
45 | // is the title aligned (text-align: xxx)?
|
---|
46 | //
|
---|
47 | var tmp:String = this.css.text_align;
|
---|
48 | switch( tmp )
|
---|
49 | {
|
---|
50 | case 'left':
|
---|
51 | this.x = this.css.margin_left;
|
---|
52 | break;
|
---|
53 |
|
---|
54 | case 'right':
|
---|
55 | this.x = this.stage.stageWidth - ( this.get_width() + this.css.margin_right );
|
---|
56 | break;
|
---|
57 |
|
---|
58 | case 'center':
|
---|
59 | default:
|
---|
60 | this.x = (this.stage.stageWidth/2) - (this.get_width()/2);
|
---|
61 | break;
|
---|
62 | }
|
---|
63 |
|
---|
64 | this.y = this.css.margin_top;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public function get_height():Number {
|
---|
68 |
|
---|
69 | if ( this.text == null )
|
---|
70 | return 0;
|
---|
71 | else
|
---|
72 | return this.css.padding_top+
|
---|
73 | this.css.margin_top+
|
---|
74 | this.getChildAt(0).height+
|
---|
75 | this.css.padding_bottom+
|
---|
76 | this.css.margin_bottom;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|