try  IUITextField

 

 

Glenn

 

 



 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
brianrusseldavis
Sent: Monday, April 07, 2008 3:25 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Fail to apply UITextFormat to UITextField in custom 
Component

 


This thread seems to be the only help out there for UITextField and
Formatting it via UITextFormat. The Adobe documentation fails to provide a
working example. So I guess I will pose the question here with a very very
simple example. Why is the following code wrong? The text displays but the
font size is not changing.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.core.UITextFormat;
import mx.core.UITextField;

private function init():void {

var myText:UITextField = new UITextField;
var myFormat:UITextFormat = new
UITextFormat(this.systemManager);
myFormat.size = 30
myText.defaultTextFormat = myFormat
myText.validateNow();
myText.text = "Hello Hello Hello!"
addChild(myText);
}

]]>
</mx:Script>
</mx:Application>

Brian Russel Davis
http://www.brickabracka.com/learning
b[at]brickabracka[dot]com 

ndkamp wrote:
> 
>> Styles can override text formating when the parent of a UITextField is
>> invalidated, but only having some formatting overridden is a little
> weird.
> 
> no, all of the formatting is overridden.
> 
>> Functionality for setting format based on style is in the
> UITextField class,
>> I think the function is validateNow()
> 
> thanks dan, that pointed me to the right direction. I traced
> validateNow() in UITextField where the format is set using styles -
> overriding all of the formatting that might have been applied using
> UITextFormat. I did toggle styleChangedFlag to false and voilĂ  - all
> the formatting using UITextFormat were applied. Now I have the choice
> to extend UITextFormat and to override validateNow() or just use
> Styles for all the formatting and forget about UITextFormat, which is
> probably the recommended way - just getting started with flex you see.
> 
> thanks again, solved.
> 
> --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , 
> "Daniel Freiman" <[EMAIL PROTECTED]> wrote:
>>
>> Styles can override text formating when the parent of a UITextField is
>> invalidated, but only having some formatting overridden is a little
> weird.
>> Functionality for setting format based on style is in the
> UITextField class,
>> I think the function is validateNow(), but I not 100% certain about
> that.
>> For future reference, I asked about font type because embeding fonts
>> incorrectly could account for the described behavior (as I originally
>> understood it), and the rendering engine for device fonts (in very
> few and
>> specific cases) also has its own quirks.
>> 
>> - Dan Freiman
>> 
>> On Feb 4, 2008 10:53 AM, ndkamp <[EMAIL PROTECTED]> wrote:
>> 
>> > ok, I found that if i wrap the textField in a sprite and add this in
>> > createChildren, then formatting will be applied correctly:
>> >
>> > var wrapper:Sprite = new Sprite();
>> > wrapper.addChild(txt);
>> > this.addChild(wrapper);
>> >
>> > Well, i'm not really comfortable with this but I think I need to look
>> > closer at styles, since formats seem to get overriden when a TextField
>> > is add directly to the component...?
>> >
>> >
>> > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>  
>> > <flexcoders%40yahoogroups.com>,
> "ndkamp"
>> > <ndkamp@> wrote:
>> > >
>> > > dan, thanks for your answer. I'm using device and/or embedded fonts,
>> > > but right here I don't really care about the fonts. I'm just puzzled
>> > > why the formatting doesn't seem to work for me. I'm using
> UITextFormat,
>> > > because of the options it gives me with anti-aliasing and
> measuring. A
>> > > I tried using TextFormat but that wont help. I did not look at
> styling
>> > > and skinning, so I'm not sure if the formats get overriden by styles
>> > > in a later stage by the framework.
>> > >
>> > >
>> > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>  
>> > > <flexcoders%40yahoogroups.com>,
>> > "Daniel Freiman" <FreimanCQ@> wrote:
>> > > >
>> > > > Are you using embeded or device fonts? Also, is there a reason
>> > you are
>> > > > using UITextFormat instead of TextFormat? Even when using with a
>> > > > UITextField, 99% of the time using UITextFormat instead of
>> > TextFormat is
>> > > > unnecessary and makes thing more complicated.
>> > > >
>> > > > - Dan Freiman
>> > > >
>> > > > On Feb 4, 2008 9:22 AM, ndkamp <ndkamp@> wrote:
>> > > >
>> > > > > Thanks for your answer. I know the text and orange background
>> > > are ok,
>> > > > > but the formats won't show. Are you really getting bold
> text, what
>> > > > > about the size and color? what if you add:
>> > > > >
>> > > > > format.italic = true,
>> > > > > format.underline = true;
>> > > > > format.font = "Georgia";
>> > > > >
>> > > > > Do they show? can't get the formats to work. Im using flex beat
>> > 3 btw.
>> > > > > thanks.
>> > > > >
>> > > > > --- In flexcoders@yahoogroups.com 
>> > > > > <mailto:flexcoders%40yahoogroups.com> 
> <flexcoders%40yahoogroups.com><flexcoders%40yahoogroups.com>, "
>> > > > > shrikant.patil" <gt_shrikant@>
>> > > > >
>> > > > > wrote:
>> > > > > >
>> > > > > >
>> > > > > > hi,
>> > > > > >
>> > > > > > i have tested u r file.... i got a orange backgrounded,
> vardana,
>> > > > > bold text
>> > > > > > saying that : The quick brown Fox...
>> > > > > >
>> > > > > > i hope it is working fine...
>> > > > > >
>> > > > > >
>> > > > > > ndkamp wrote:
>> > > > > > >
>> > > > > > > I try to apply UITextFormat to an UITextField in a custom
>> > > component
>> > > > > > > but the new format won't show. what am i doing wrong?
>> > > > > > >
>> > > > > > > package tests.components
>> > > > > > > {
>> > > > > > > import flash.text.TextLineMetrics;
>> > > > > > > import mx.core.UIComponent;
>> > > > > > > import mx.core.UITextField;
>> > > > > > > import mx.core.UITextFormat;
>> > > > > > >
>> > > > > > > public class TestCustomComponent extends UIComponent
>> > > > > > > {
>> > > > > > > private var txt:UITextField;
>> > > > > > >
>> > > > > > > public function TestCustomComponent()
>> > > > > > > {
>> > > > > > > super();
>> > > > > > > }
>> > > > > > >
>> > > > > > > /*
>> > > > > > > * Create the TextField add some TextFormat and add it to
>> > > > > > > * the displayList.
>> > > > > > > */
>> > > > > > > override protected function createChildren():void {
>> > > > > > > super.createChildren();
>> > > > > > >
>> > > > > > > //Use TextFormat and apply some formats
>> > > > > > > var format:UITextFormat = new
> UITextFormat(this.systemManager);
>> > > > > > > format.font = "Verdana";
>> > > > > > > format.bold = true;
>> > > > > > > format.color = 0x804020;
>> > > > > > > format.size = 20;
>> > > > > > >
>> > > > > > > //The TextField that should be formated
>> > > > > > > txt = new UITextField();
>> > > > > > >
>> > > > > > > //The documentation says TextFormat won't be applied
>> > > > > > > //when a styleSheet is in use, naive approach to so set
> this to
>> > > > > null
>> > > > > > > //is this enough?
>> > > > > > > txt.styleSheet = null;
>> > > > > > > txt.styleName = null;
>> > > > > > >
>> > > > > > > //Apply the TextFormat for defaults and all current Text
>> > > > > > > txt.defaultTextFormat = format;
>> > > > > > > txt.text = "The quick brown Fox...";
>> > > > > > > this.addChild(txt);
>> > > > > > >
>> > > > > > > }
>> > > > > > >
>> > > > > > > /*
>> > > > > > > * Sets the measures to the width of the text plus some
> offset
>> > > > > > > */
>> > > > > > > override protected function measure():void {
>> > > > > > > super.measure();
>> > > > > > > var metrics:TextLineMetrics = txt.getLineMetrics(0);
>> > > > > > > this.measuredWidth = this.measuredMinWidth =
> metrics.width + 20;
>> > > > > > > this.measuredHeight = this.measuredMinHeight =
>> > metrics.height + 2;
>> > > > > > > }
>> > > > > > >
>> > > > > > > /*
>> > > > > > > * Add a rounded Rectangle at the back of the TextField
>> > > > > > > */
>> > > > > > > override protected function
>> > > updateDisplayList(unscaledWidth:Number,
>> > > > > > > unscaledHeight:Number):void {
>> > > > > > > super.updateDisplayList(unscaledWidth, unscaledHeight);
>> > > > > > > this.graphics.beginFill(0xff8800, 1);
>> > > > > > > this.graphics.drawRoundRect(0, 0, unscaledWidth,
>> > > > > unscaledHeight, 10);
>> > > > > > > this.graphics.endFill();
>> > > > > > > txt.setActualSize(unscaledWidth, unscaledHeight);
>> > > > > > > }
>> > > > > > > }
>> > > > > > > }
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > >
>> > > > > > --
>> > > > > > View this message in context:
>> > > > >
>> > > > >
>> > >
>> >
>> >
> http://www.nabble.com/Fail-to-apply-UITextFormat-to-UITextField-in-custom-Component-tp15266357p15267393.html
>> > > > > > Sent from the FlexCoders mailing list archive at Nabble.com.
>> > > > > >
>> > > > >
>> > > > >
>> > > > >
>> > > >
>> > >
>> >
>> > 
>> >
>>
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Fail-to-apply-UITextFormat-to-UITextField-in-custom-Component-tp15266357p16532604.html
Sent from the FlexCoders mailing list archive at Nabble.com.

 

<<image001.png>>

Reply via email to