Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
3 - 1
import mx.transitions.Tween;
2
 
3
class MenuDescObj {
4
 
5
    private var menuItem:MovieClip;
6
    private var menuText:TextField;
7
    private var menuFont:TextFormat;
8
 
9
    private var menuVisible:Boolean = false;
10
    private var inUse:Boolean = false;
11
 
12
    private var textWidth:Number;
13
    private var fontSize:Number;
14
    private var unitHeight:Number;
15
    private var maxHeight:Number;
16
 
17
    private var scrollTime:Number;
18
 
19
    function MenuDescObj (mainScene:MovieClip, font:TextFormat, scrollTime:Number, left:Number, width:Number, top:Number, maxHeight:Number, unitHeight:Number) {
20
        this.scrollTime = scrollTime;
21
        menuItem = mainScene.createEmptyMovieClip("menuItem", mainScene.getNextHighestDepth());
22
        menuItem._x = left;
23
        menuItem._y = top;
24
        menuFont = font;
25
        this.unitHeight = unitHeight;
26
        this.maxHeight = maxHeight;
27
        menuText = menuItem.createTextField("menuText", 1, 0, 0, 0, 10);
28
        menuText.embedFonts = true;
29
 
30
        //size the textfield, strange way
31
        menuText.text = "-";
32
        menuText.setTextFormat(menuFont);
33
        menuText.autoSize = "left";
34
        fontSize = menuText._height;
35
        menuText.autoSize = "none";
36
 
37
        menuText._width = width*fontSize / unitHeight * 1.2;    //(1.2 to fit more text)
38
        menuItem._width = width;
39
 
40
        menuText.multiline = true;
41
        //menuText.html = true;
42
        menuText.wordWrap = true;
43
        menuText.selectable = false;
44
        //menuText.textColor = 0xFF0000;
45
        menuText.type = "dynamic";
46
        menuItem._visible = false;
47
 
48
        menuText._height = fontSize;
49
        menuItem._height = unitHeight;
50
 
51
 
52
    }       //end constructor
53
 
54
    public function update(text:String) {
55
        //rutinen skall skrivas om, då objektet laddas skall man testa raderna vs height
56
        //så det görs EN gång
57
 
58
        menuText.text = text;
59
        //menuText.htmlText
60
        menuText.setTextFormat(menuFont);
61
        menuText._height = fontSize;
62
        menuItem._height = unitHeight;
63
 
64
        //trace("bottom: " + menuText.bottomScroll + " max: " + menuText.maxscroll);
65
        if (text.length > 0) {
66
 
67
            for (var i:Number = fontSize; true; i = i+fontSize/5) {
68
                menuText._height = i*fontSize/unitHeight;
69
                menuItem._height = i;
70
                menuText.text = text;
71
                menuText.setTextFormat(menuFont);
72
                if (menuText.maxscroll == 1) {
73
                    break;
74
                }
75
                if (menuItem._height > maxHeight) {
76
                    menuText._height = (i-fontSize/5)*fontSize/unitHeight;
77
                    menuItem._height = (i-fontSize/5);
78
 
79
                    break;
80
                }
81
 
82
                //TODO: ta bort denna!
83
                if (i > 500) {
84
                    trace(menuItem._height + " " + maxHeight);
85
                    break;
86
                }
87
                //trace(menuText.maxscroll + " " + menuText.scroll + " " + menuText.bottomScroll);
88
                //trace(menuText.bottomScroll + " fontsize: " + fontSize + " i: " + i + " menutext-height: " + menuText._height);
89
            }
90
        } else {
91
            menuItem._height = 0;
92
        }
93
 
94
    }
95
 
96
    //public function getSize
97
 
98
    public function appear() {
99
        inUse = true;
100
        menuItem._visible = (menuVisible && inUse);
101
        var test:Tween = new Tween(menuText, "_alpha", null, 5, 100, scrollTime, true);
102
 
103
    }
104
 
105
    public function hide() {
106
        inUse = false;
107
        menuItem._visible = (menuVisible && inUse);
108
        //var test:Tween = new Tween(menuText, "_alpha", null, 5, 100, 1, true);
109
 
110
    }
111
 
112
    public function setText(text:String) {
113
        menuText.text = text;
114
        menuText.setTextFormat(menuFont);
115
    }
116
 
117
    public function visible(isVisible:Boolean) {
118
        menuVisible = isVisible;
119
        menuItem._visible = (menuVisible && inUse);
120
    }  
121
 
122
    public function getTop():Number {
123
        return menuItem._y;
124
    }
125
    public function getBottom():Number {
126
        return menuItem._y + menuItem._height;
127
    }
128
    /*public function setTop(top:Number) {
129
        //animera senare?
130
        //menuItem._visible = (menuVisible && inUse);
131
        menuItem._y = top;
132
    }*/
133
    public function setHeight(height:Number) {
134
        //animera senare?
135
        //menuItem._visible = (menuVisible && inUse);
136
        menuItem._height = height;
137
    }
138
 
139
}