You need to create the CSSStyleDeclaration only once.
var css:CSSStyleDeclaration = new CSSStyleDeclaration();
css.setStyle("borderColor", 0x316AC5);
css.setStyle("tileAlphas", [1,1]);
css.setStyle("borderColor", 0x316AC5);
css.setStyle("borderAlpha", 1.0);
css.setStyle("fillColor", 0x316AC5);
css.setStyle("fillAlpha", 0.5);
StyleManager.setStyleDeclaration("DragSelection", css, true);
regards,
Muzak
----- Original Message -----
From: "Mark Ingram" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, June 01, 2007 12:53 PM
Subject: RE: [flexcoders] Best way to set styles in actionscript?
OK, that doesn't work. What's wrong with my code?
private static var m_staticInitialised:Boolean =
DragSelection.staticConstructor();
private static function staticConstructor():Boolean
{
if (!StyleManager.getStyleDeclaration("DragSelection"))
{
// If there is no CSS definition for DragSelection,
// then create one and set the default value.
var borderColorStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
borderColorStyle.setStyle("borderColor", 0x316AC5);
var borderAlphaStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
borderAlphaStyle.setStyle("borderAlpha", 1.0);
var fillColorStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
fillColorStyle.setStyle("fillColor", 0x316AC5);
var fillAlphaStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
fillAlphaStyle.setStyle("fillAlpha", 0.5);
StyleManager.setStyleDeclaration("DragSelection", borderColorStyle, true);
StyleManager.setStyleDeclaration("DragSelection", borderAlphaStyle, true);
StyleManager.setStyleDeclaration("DragSelection", fillColorStyle, true);
StyleManager.setStyleDeclaration("DragSelection", fillAlphaStyle, true);
}
return true;
}
The values that come out during updateDisplayList are:
borderColor: 0xb7babc (grey)
borderAlpha: 1
fillColor: 0xffffff (white)
fillAlpha: 0.5
It seems the border and fill colours are being overwritten somewhere
(the parent background is white)!
I checked in styleChanged function, but the "styleProp" value just came
through as null every time!
Thanks,
Mark