Flex Style Introspection

By | August 16, 2009

If you have ever used the Flex introspection method describeType(), you certainly have noticed it doesn’t output any style metadata. The only way I found so far was to instantiate the UIComponent type I’m looking at and call the function regenerateStyleCache(false). The entire list of available styles is then accessible via the properties inheritingStyles and nonInheritingStyles. Generating the style cache is computation-intensive so like most reflection and introspection operations make effective use of it :)

Some code example after the jump…

ActionScript
< view plain text >
  1. var componentClass:Class = getDefinitionByName("mx.controls.CheckBox") as Class;
  2. var component:UIComponent = new componentClass();
  3. component.regenerateStyleCache(false);
  4. trace(ObjectUtil.toString(component.nonInheritingStyles));
  5. trace(ObjectUtil.toString(component.inheritingStyles));

will output…


(Object)#0
backgroundAlpha = 1
backgroundSize = "auto"
bevel = true
borderAlpha = 1
borderCapColor = 9542041
borderColor = 12040892
borderSides = "left top right bottom"
borderSkin = (mx.skins.halo::HaloBorder)
borderStyle = "inset"
borderThickness = 1
buttonColor = 7305079
closeDuration = 250
color = 734012
cornerRadius = 4
disabledColor = 11187123
disabledIcon = (null)
disabledIconColor = 10066329
disabledSkin = (null)
downIcon = (null)
downSkin = (null)
dropShadowColor = 0
dropShadowEnabled = false
embedFonts = false
errorColor = 16711680
fillAlphas = (Array)#1
[0] 0.6
[1] 0.4
[2] 0.75
[3] 0.65
fillColor = 16777215
fillColors = (Array)#2
[0] 16777215
[1] 13421772
[2] 16777215
[3] 15658734
filled = true
focusAlpha = 0.4
focusBlendMode = "normal"
focusRoundedCorners = "tl tr bl br"
focusSkin = (mx.skins.halo::HaloFocusRect)
focusThickness = 2
fontAntiAliasType = "advanced"
fontFamily = "Verdana"
fontGridFitType = "pixel"
fontSharpness = 0
fontSize = 10
fontStyle = "normal"
fontThickness = 0
fontWeight = "normal"
highlightAlphas = (Array)#3
[0] 0.3
[1] 0
horizontalAlign = "left"
horizontalGap = 5
horizontalGridLineColor = 16250871
horizontalGridLines = false
icon = (mx.skins.halo::CheckBoxIcon)
iconColor = 2831164
indentation = 17
indicatorGap = 14
kerning = false
leading = 2
letterSpacing = 0
modalTransparency = 0.5
modalTransparencyBlur = 3
modalTransparencyColor = 14540253
modalTransparencyDuration = 100
openDuration = 250
overIcon = (null)
overSkin = (null)
paddingBottom = 2
paddingLeft = 0
paddingRight = 0
paddingTop = 2
repeatDelay = 500
repeatInterval = 35
roundedBottomCorners = true
selectedDisabledIcon = (null)
selectedDisabledSkin = (null)
selectedDownIcon = (null)
selectedDownSkin = (null)
selectedOverIcon = (null)
selectedOverSkin = (null)
selectedUpIcon = (null)
selectedUpSkin = (null)
selectionDisabledColor = 14540253
selectionDuration = 250
shadowCapColor = 14015965
shadowColor = 15658734
shadowDirection = "center"
shadowDistance = 2
skin = (null)
stroked = false
strokeWidth = 1
textAlign = "left"
textDecoration = "none"
textIndent = 0
textRollOverColor = 2831164
textSelectedColor = 2831164
themeColor = 40447
upIcon = (null)
upSkin = (null)
useRollOver = true
version = "3.0.0"
verticalAlign = "top"
verticalGap = 2
verticalGridLineColor = 14015965
verticalGridLines = true
(Object)#0
backgroundAlpha = 1
backgroundSize = "auto"
bevel = true
borderAlpha = 1
borderCapColor = 9542041
borderColor = 12040892
borderSides = "left top right bottom"
borderSkin = (mx.skins.halo::HaloBorder)
borderStyle = "inset"
borderThickness = 1
buttonColor = 7305079
closeDuration = 250
color = 734012
cornerRadius = 4
disabledColor = 11187123
disabledIcon = (null)
disabledIconColor = 10066329
disabledSkin = (null)
downIcon = (null)
downSkin = (null)
dropShadowColor = 0
dropShadowEnabled = false
embedFonts = false
errorColor = 16711680
fillAlphas = (Array)#1
[0] 0.6
[1] 0.4
[2] 0.75
[3] 0.65
fillColor = 16777215
fillColors = (Array)#2
[0] 16777215
[1] 13421772
[2] 16777215
[3] 15658734
filled = true
focusAlpha = 0.4
focusBlendMode = "normal"
focusRoundedCorners = "tl tr bl br"
focusSkin = (mx.skins.halo::HaloFocusRect)
focusThickness = 2
fontAntiAliasType = "advanced"
fontFamily = "Verdana"
fontGridFitType = "pixel"
fontSharpness = 0
fontSize = 10
fontStyle = "normal"
fontThickness = 0
fontWeight = "normal"
highlightAlphas = (Array)#3
[0] 0.3
[1] 0
horizontalAlign = "left"
horizontalGap = 5
horizontalGridLineColor = 16250871
horizontalGridLines = false
icon = (mx.skins.halo::CheckBoxIcon)
iconColor = 2831164
indentation = 17
indicatorGap = 14
kerning = false
leading = 2
letterSpacing = 0
modalTransparency = 0.5
modalTransparencyBlur = 3
modalTransparencyColor = 14540253
modalTransparencyDuration = 100
openDuration = 250
overIcon = (null)
overSkin = (null)
paddingBottom = 2
paddingLeft = 0
paddingRight = 0
paddingTop = 2
repeatDelay = 500
repeatInterval = 35
roundedBottomCorners = true
selectedDisabledIcon = (null)
selectedDisabledSkin = (null)
selectedDownIcon = (null)
selectedDownSkin = (null)
selectedOverIcon = (null)
selectedOverSkin = (null)
selectedUpIcon = (null)
selectedUpSkin = (null)
selectionDisabledColor = 14540253
selectionDuration = 250
shadowCapColor = 14015965
shadowColor = 15658734
shadowDirection = "center"
shadowDistance = 2
skin = (null)
stroked = false
strokeWidth = 1
textAlign = "left"
textDecoration = "none"
textIndent = 0
textRollOverColor = 2831164
textSelectedColor = 2831164
themeColor = 40447
upIcon = (null)
upSkin = (null)
useRollOver = true
version = "3.0.0"
verticalAlign = "top"
verticalGap = 2
verticalGridLineColor = 14015965
verticalGridLines = true

Leave a Reply

*

* Copy This Password *

* Type Or Paste Password Here *

135,313 Spam Comments Blocked so far by Spam Free Wordpress