Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing text style dynamically in flex

Posted on 2009-07-13
2
Medium Priority
?
1,087 Views
Last Modified: 2012-05-07
Hi
I am working with flex piece of code there i want to change the text label style dynamically by taking the input from the user.
0
Comment
Question by:sandeep_manne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 24858033
Hi sandeep,
I took the Label example from the Flex documentation and extended it with an extra button "Click to change the style dynamically".
Fill in a (valid) color and press the button.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<!-- Simple example to demonstrate the Label control -->
 
    <mx:Script>
        <![CDATA[
      
            private var htmlData:String="<br>This label displays <b>bold</b> and <i>italic</i> HTML-formatted text.";
                                         
            // Event handler function to change the image size.
            private function displayHTML():void {
                simpleLabel.htmlText= htmlData;
            }
          
            // Event handler function to change the image size.
            private function displayText():void {
                simpleLabel.text="This Label displays plain text.";
            }
            
            private function changeStyle():void {
            	simpleLabel.setStyle("color", "0x"+color.text); // Red
            }         
        ]]>
    </mx:Script>
 
  <mx:Panel title="Label Control Example" height="75%" width="75%" 
      paddingTop="10" paddingLeft="10">
    
      <mx:Label id="simpleLabel" text="This Label displays plain text."/>
      <mx:Button id="Display" label="Click to display HTML Text" click="displayHTML();"/>
      <mx:Button id="Clear" label="Click to display plain text" click="displayText();"/>
      <mx:HBox>
        <mx:Label text="Color of the text in hex (ex. FF0000 for red):"/>
        <mx:TextInput id="color"/>
      	<mx:Button id="Style" label="Click to change the style dynamically" click="changeStyle();"/>
      </mx:HBox>
      
  
  </mx:Panel>
</mx:Application>

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24858441
Thanx 4 axxepting
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question