Skip to main content
Participant
June 4, 2012
Answered

Styling text from URLLoader in AIR for iOS

  • June 4, 2012
  • 1 reply
  • 723 views

so i have been trying to figure this out for the last couple of days, the code is below without any styling. I have tried creating a TextFormat instance and have tried just applying the properties to myTextField_txt and I even tried to style the text on the website first and then change myTextField_txt to htmlText, unfortunately that didn't work either. I just want to change the size and color of the text, any help would be greatly appreciated, thanks!

var myTextLoader:URLLoader = new URLLoader();

var myTextField_txt:TextField = new TextField();

myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

myTextField_txt.x = 100;

myTextField_txt.y = 100;

function onLoaded(e:Event):void {

myTextField_txt.text = e.target.data;

addChild(myTextField_txt);

}

myTextLoader.load(new URLRequest("..."));

This topic has been closed for replies.
Correct answer chris.campbell

Would you mind reposting this question over on the Flash Professional forums?  This forum is primarily for end users, the Pro forums will get you in touch with a wider developer audience.

That said, I was able to get TextFormat to work using the following code in Flash Builder:

<?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:Script>

                    <![CDATA[

                              import mx.core.UIComponent;

 

                              public function init():void

                              {

                                   var label:TextField = new TextField();

                                   var format:TextFormat = new TextFormat();

 

                                   format.color = 0xFF0000;

 

                                   label.defaultTextFormat = format;

 

                                   label.text = "this is a test ";

 

                                   var l:UIComponent = new UIComponent();

                                   l.addChild(label);

                                   this.addElement(l);

                              }

                    ]]>

          </fx:Script>

</s:Application>

1 reply

chris.campbell
chris.campbellCorrect answer
Legend
June 6, 2012

Would you mind reposting this question over on the Flash Professional forums?  This forum is primarily for end users, the Pro forums will get you in touch with a wider developer audience.

That said, I was able to get TextFormat to work using the following code in Flash Builder:

<?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:Script>

                    <![CDATA[

                              import mx.core.UIComponent;

 

                              public function init():void

                              {

                                   var label:TextField = new TextField();

                                   var format:TextFormat = new TextFormat();

 

                                   format.color = 0xFF0000;

 

                                   label.defaultTextFormat = format;

 

                                   label.text = "this is a test ";

 

                                   var l:UIComponent = new UIComponent();

                                   l.addChild(label);

                                   this.addElement(l);

                              }

                    ]]>

          </fx:Script>

</s:Application>

MaxemMAuthor
Participant
June 7, 2012

Wow. it worked. Thank you so much. I tried the the TextFormat var before but it didn't work, I must've screwed it up somehow. Anyway, I reposted the discussion in flash pro general forums so I'm going to paste your reply over there so other people can find it.