snippet: view plain - save this
1 package programmaticSkinClasses {
2
3 import mx.core.UIComponent;
4 import flash.filters.DropShadowFilter;
5
6 public class GradientRectangleSkin extends UIComponent {
7
8 import flash.display.Graphics;
9 import flash.geom.Rectangle;
10 import mx.graphics.GradientEntry;
11 import mx.graphics.LinearGradient;
12
13 protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
14 super.updateDisplayList(unscaledWidth,unscaledHeight);
15 var w:Number = unscaledWidth;
16 var h:Number = unscaledHeight;
17
18 // hold the values of the gradients depending on button state
19 var backgroundFillColor:Number;
20 var backgroundFillColor2:Number;
21 var backgroundFillColor3:Number;
22
23
24 var fill:LinearGradient = new LinearGradient();
25
26 // reference the graphics object of this skin class
27 var g:Graphics = graphics;
28 g.clear();
29
30 // which skin is the button currently looking for? Which skin to use?
31 switch (name) {
32 case "upSkin":
33 backgroundFillColor = 0x929292;
34 backgroundFillColor2 = 0x000000;
35 break;
36 case "overSkin":
37 backgroundFillColor = 0x696969;
38 backgroundFillColor2 = 0x504F4F;
39 break;
40 case "downSkin":
41 backgroundFillColor = 0x888888;
42 backgroundFillColor2 = 0x777777;
43 color: 0xFF0000;
44 break;
45 case "disabledSkin":
46 backgroundFillColor = 0xCCCCCC;
47 backgroundFillColor2 = 0xCCCCCC;
48 break;
49 }
50 // depending on which state the button's in, we set our color for the
51 // gradients on the skin
52 var g1:GradientEntry = new GradientEntry(backgroundFillColor,.10,100);
53 var g2:GradientEntry = new GradientEntry(backgroundFillColor2,.60,100);
54
55 fill.entries = [g1,g2];
56 fill.angle = 90;
57 // fill the rectangle
58 g.moveTo(0,0);
59 fill.begin(g,new Rectangle(0,0,w,h));
60 g.lineTo(w,0);
61 g.lineTo(w,h);
62 g.lineTo(0,h);
63 g.lineTo(0,0);
64 fill.end(g);
65 // if we're not showing the down skin, show the shadow. Otherwise hide it on the "down state" to look like it's being pressed
66 if(name != "downSkin") {
67 filters = [new DropShadowFilter(4, 45,0x000000,.2)];
68 }
69 }
70 }
71 }

0 comments