Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:34:51+00:00 2026-06-13T05:34:51+00:00

This problem is driving me bananas because it seems to be so simple. I’m

  • 0

This problem is driving me bananas because it seems to be so simple. I’m trying to apply a text format to a text field created with code and have the formatting remain applied to the textfield if the text changes. The following code works as expected in raw AS3. I’ve broken down these examples to be as simplistic as possible.

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;

    public class Testing extends Sprite
    {
        public function Testing()
        {
            var tf:TextField = new TextField();
            addChild(tf);
            tf.border = true;

            var tfor:TextFormat = new TextFormat();
            tfor.align = 'right';
            tfor.size = 30;

            tf.defaultTextFormat = tfor;

            tf.text = 'Testing';

        }
    }
}

However, similar code in Flex does not behave the same way. The following code results in the text not being formatted correctly.

<?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="_create(event)">
    <fx:Script>
        <![CDATA[
            import mx.core.UITextField;
            import mx.events.FlexEvent;

            protected function _create(event:FlexEvent):void
            {
                var tf:UITextField = new UITextField();
                ui.addChild(tf);
                tf.border = true;

                var tfor:TextFormat = new TextFormat();
                tfor.align = 'right';
                tfor.size = 30;

                tf.defaultTextFormat = tfor;

                tf.text = 'Testing';            
            }

        ]]>
    </fx:Script>

    <mx:UIComponent id="ui" width="100%" height="100%" />

</s:Application>

I realize that I could just use a Flex component as the text field and stick formatting on it that way, but this code needs to play nicely with previously written code. Thanks for your help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:34:53+00:00Added an answer on June 13, 2026 at 5:34 am

    Below code may help you: – instead of adding it to UIComponent add it to SpriteVisualElement it will work.

    <?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="_create(event)">
        <fx:Script>
            <![CDATA[
                import mx.core.UITextField;
                import mx.events.FlexEvent;
    
                protected function _create(event:FlexEvent):void
                {
                    var tf:UITextField = new UITextField();
                    ui.addChild(tf);
                    tf.border = true;
    
                    var tfor:TextFormat = new TextFormat();
                    tfor.align = 'right';
                    tfor.size = 30;
    
                    tf.defaultTextFormat = tfor;
    
                    tf.text = 'Testing';            
                }
    
            ]]>
        </fx:Script>
        <s:SpriteVisualElement id="ui" width="100%" height="100%" />
    
    </s:Application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is driving me a bit crazy. The code seems to be segmentation
Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning
This problem seems very simple to me, but I've been unable to fix it,
This has been driving me bananas! I'm trying to get my app to publish
This problem is driving me crazy because I am not sure why this just
This problem is driving me crazy. I'm trying to change the viewController when the
This problem is driving me up the wall. This is for a very simple
This problem is driving me crazy. I have the following code: 'unprotect sheet If.Range(Start).Row+1<.Range(End).Row
I've been having this problem for a while and it's driving me nuts. I'm
This is NOT a duplicate question, and the problem is driving me crazy. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.