Share on Google+Share on Google+

Style using styleManager in Flex4

Advertisement
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"/>

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

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

</s:Panel>

</s:Application>

Output:

Running Application:

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

Download this code

Advertisements

Advertisement

Posted on: June 21, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.