Amy
Wed, 25 Jun 2008 20:41:36 -0700
--- In flexcoders@yahoogroups.com, "Amy" <[EMAIL PROTECTED]> wrote: > > --- In flexcoders@yahoogroups.com, "Amy" <amyblankenship@> wrote: > > > > I'm trying to extend AdvancedDataGridItemRenderer to allow the > > styleFunction to set both the backgroundColor and the alpha of the > > item in. I've used a combination of the custom style example in > the > > docs and the example here > http://flexpearls.blogspot.com/2008/02/row- > > background-color-in.html. The problem I'm having is that it > doesn't > > matter what you set the alpha property to, it doesn't affect the > > visual appearance of the component. > > > > I tried using the graphics object to draw the box, but it seems > like > > the base component doesn't support this. If anyone has any ideas, > > please share. > > OK, I think if I could somehow add a sprite to the component, I could > make this work, but instead of addChild, it has AddChild, which shows > three arguments in code hinting but throws a compiler error if I give > it more than one. If I give it a sprite as the one argument, it > gives me a runtime error. > > I can't look to see where it is drawing the background in, because > that's in one of the Flash classes. It doesn't look like those are > included in the source that comes with FB3. > > Anyone? Anyone? Buehler? >
OK, I've tried the following code, but despite the fact that the
alphaMultiplier is set properly, the background transparency isn't
changing. That's probably a good thing, since it would probably make
the text semitransparent as well, but I am not sure how to get hold
of just the background.
My styleFunction is just setting the background color for now, so
getStyle is returning the default .5
Here's the code:
1package com.magnoliamultimedia.views
2{
3 import flash.geom.ColorTransform;
4 import flash.geom.Transform;
5
6 import
mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;
7 import mx.styles.CSSStyleDeclaration;
8 import mx.styles.StyleManager;
9
10 [Style(name="backgroundColor", format="Color", inherit="no")]
11 [Style(name="alpha", type="int", format="Number",
inherit="yes")]
12 public class ADGItemRendererPatch extends
AdvancedDataGridItemRenderer
13 {
14
15 //this gets the styles ready to go for any instance
of this class
16 private static var hasTypeSelector:Boolean =
classConstruct();
17
18 //Define the flag to indicate that a style property
changed.
19 private var _StylePropChanged:Boolean = true;
20
21 private var
_backgroundColor:uint=StyleManager.NOT_A_COLOR;
22
23 //construtor
24 public function ADGItemRendererPatch()
25 {
26 super();
27 }
28
29
30
31 // Define a static method.
32 private static function classConstruct():Boolean {
33 if (!StyleManager.getStyleDeclaration
('ADGItemRendererPatch'))
34 {
35 // If there is no CSS definition for
StyledRectangle,
36 // then create one and set the default value.
37 var myStyles:CSSStyleDeclaration = new
CSSStyleDeclaration();
38 myStyles.defaultFactory = function():void
39 {
40 //default green background
41 this.backGroundColor = 0x33FF33;
42 this.alpha = .5;
43 }
44 StyleManager.setStyleDeclaration
("ADGItemRendererPatch", myStyles, true);
45 return false;
46 }
47 return true;
48 }
49 /* #######################################
50 OVERRIDDEN INHERITED FUNCTIONALITY
51 ###################################### */
52 //detect changes in the new style.
53 override public function styleChanged
(styleProp:String):void {
54
55 super.styleChanged(styleProp);
56
57 // Check to see if style changed.
58 if (styleProp=="backgroundColor" || styleProp=="alpha")
59 {
60 _StylePropChanged=true;
61 invalidateDisplayList();
62 return;
63 }
64 }
65 override public function validateProperties():void{
66 super.validateProperties();
67 //use any typeSelector that might be defined
68 if (hasTypeSelector){
69 this.styleName = this.className;
70 }
71 }
72 override public function validateNow():void
73 {
74 super.validateNow();
75 // Check to see if style changed.
76 if (_StylePropChanged)
77 {
78 _backgroundColor=getStyle('backgroundColor')
79 if (_backgroundColor!=StyleManager.NOT_A_COLOR){
80 this.background=true;
81
82 this.backgroundColor=_backgroundColor;
83 }else{
84 this.background=false;
85 }
86
87 var t:Transform=new Transform(this);
88 var ct:ColorTransform=new ColorTransform();
89 ct.alphaMultiplier=getStyle('alpha');
90 t.colorTransform=ct;
91 trace
(this.transform.colorTransform.alphaMultiplier, getStyle('alpha'),
ct.alphaMultiplier, transform.colorTransform.alphaOffset);
92 //(0.5 0.5 0.5 0)
93 _StylePropChanged=false;
94 }
95 }
96 }
97}