Style using styleManager in Flex4


 

Style using styleManager in Flex4

You can use the styleManager for set the style of component.

You can use the styleManager for set the style of component.

Style using styleManager in Flex4:

You can use the styleManager for set the style of component. In this example we use a styleManager for set the property of components. The syntax is following:

styleManager.getStyleDeclaration(style_name).setStyle("property", value);

We have to use a getStyleDeclaration() method. you can use the three type of selector in it: Type Selector, Class Selector and Global Style.

Example:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx"

minWidth="955" minHeight="600"

creationComplete="init()">

<fx:Style>

@namespace s "library://ns.adobe.com/flex/spark";

@namespace mx "library://ns.adobe.com/flex/mx";

.label{

font-family:"Verdana";

font-size:12px;

color:#900000;

}

</fx:Style>

<fx:Script>

<![CDATA[

public function init():void{

// set style using style manager

styleManager.getStyleDeclaration("spark.components.Button").setStyle("fontSize",15);

styleManager.getStyleDeclaration("spark.components.Button").setStyle("color", "blue");

}

]]>

</fx:Script>

<s:Panel title="Style using Style manager Example" width="288" height="182">

<s:Button id="btn"

label="Submit"

x="85" y="31"/>

0

<s:Label text="This is a Style manager example."

x="34" y="84" styleName="label"/>

</s:Panel>

1

</s:Application>

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

2

Download this code

Ads