Mega Code Archive

 
Categories / Flex / Style
 

Customize Styles at Runtime

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">     <mx:Script>                      private function changeColor():void             {                 holder.setStyle( "backgroundColor", getRandomColor() );                 labelField.setStyle( "color", getRandomColor() );             }             private function getRandomColor():uint             {                 return randomValue() << 16 ^ randomValue() << 8 ^ randomValue();             }             private function randomValue():Number             {                 return (Math.random() * 512) - 255;             }            </mx:Script>     <mx:VBox id="holder" width="200" height="200">         <mx:Label id="labelField" text="Hello Flex!" styleName="header" />         <mx:Button label="Change" click="changeColor();" />     </mx:VBox> </mx:Application>