Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding line breaks in AS3

Guest
Apr 06, 2011 Apr 06, 2011

I'm attempting to add line breaks after the code I've included below. I know that I need to add a "\n" after the line of text, but I haven't had any success.


textField.appendText(""+ bldg.S11.Title.text())
textField.appendText("Square Footage: "+ bldg.S11.SF.text())
textField.appendText("Tenant: "+ bldg.S11.Tenant.text())
textField.appendText("Status: "+ bldg.S11.Status.text())

Thank you.

TOPICS
ActionScript
11.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 06, 2011 Apr 06, 2011

You have to have a TextField called "textField" and it needs "wordWrap" and "multiline" properties set to true (as in kglad's post - but there is no "html" property for AS3 TextField class).

Then you can either use html text or normal text:

           // html text

            var myText:String = new String();

            for(var i:uint = 0; i < bldg.S11.length(); i++){
                myText += bldg.S11.Title + "<br />";
                myText += "Square Footage: " + bldg.S11.SF + "<br />";
           

...
Translate
Engaged ,
Apr 06, 2011 Apr 06, 2011

if textField is rendering htmlText (i.e. - textField.htmlText = "";), you can use <br> tags, i.e.:

textField.appendText(""+ bldg.S11.Title.text() + '<br>');

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 06, 2011 Apr 06, 2011

Adding the  + '<br>'); to the end of the line of the text now adds <br> between each line. I have set the text box to render text as html if that makes a difference.

Shops 1 - Unit 101<br>Square Footage: 4,204<br>Tenant: TBD<br>Status: Available<br>

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2011 Apr 06, 2011

you must assign htmlText, not text, to use html in your strings.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 06, 2011 Apr 06, 2011

Heres my code thus far. I made the changes from what I understood you were talking about. This generates an error: 1195: Attempted access of inaccessible method htmlText through a reference with static type flash.text:TextField.

I found this code online which says I need to add somewhere. I'm not sure where.

var myText:String = "<p>This is <b>some</b> content to <i>render</i> as <u>HTML</u> text.</p>"; 
testField.htmlText = myText;

I'm also not sure what the "myText" would change to in regard to my code.

My Code:

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.addEventListener(Event.COMPLETE, showXML);

xmlLoader.load(new URLRequest("Talega.xml"));

function showXML(e:Event):void {

XML.ignoreWhitespace = true;

var bldg:XML = new XML(e.target.data);

var i:Number;

for (i=0; i < bldg.S11.length(); i++) {

textField.htmlText(""+ bldg.S11.Title.text() + '<br>');

textField.htmlText("Square Footage: "+ bldg.S11.SF.text() + '<br>');

textField.htmlText("Tenant: "+ bldg.S11.Tenant.text() + '<br>');

textField.htmlText("Status: "+ bldg.S11.Status.text() + '<br>');

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2011 Apr 06, 2011

my error.  use:


var myText:String = "<p>This is <b>some</b> content to <i>render</i> as <u>HTML</u> text.</p>"; 
testField.html = true;
testField.multiline=true;
testField.wordWrap=true;
testField.text = myText;


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2011 Apr 06, 2011

You have to have a TextField called "textField" and it needs "wordWrap" and "multiline" properties set to true (as in kglad's post - but there is no "html" property for AS3 TextField class).

Then you can either use html text or normal text:

           // html text

            var myText:String = new String();

            for(var i:uint = 0; i < bldg.S11.length(); i++){
                myText += bldg.S11.Title + "<br />";
                myText += "Square Footage: " + bldg.S11.SF + "<br />";
                myText += "Tenant: " + bldg.S11.Tenant + "<br />";
                myText += "Status: " + bldg.S11.Status + "<br />";
            }
           
            textField.htmlText = myText;

           // normal text

           var myText:String = new String();

           for(var i:uint = 0; i < bldg.S11.length(); i++){
                myText += bldg.S11.Title + "\n";
                myText += "Square Footage: " + bldg.S11.SF + "\n";
                myText += "Tenant: " + bldg.S11.Tenant + "\n";
                myText += "Status: " + bldg.S11.Status + "\n";
            }
           
            textField.text = myText;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 06, 2011 Apr 06, 2011

Success! Thank you.

I have one more question that I think you can answer rather quickly.

I have a button that will load an XML file. I have the button code (below) and then the xmlLoader code shown below that.

What would I need to add and to where to make the event.target load the XML text. There are a series of these in the same fla file so I would have this same line of coding placed under each movie clip.

Button:

s63.addEventListener (MouseEvent.CLICK, onClick);

s63.addEventListener(MouseEvent.ROLL_OVER, mcOver);

s63.addEventListener(MouseEvent.ROLL_OUT, mcOut);

function mcOut( event:MouseEvent):void

{

event.target.alpha = 1;

}

function mcOver( event:MouseEvent):void

{

event.target.alpha = 0.5;

}

function onClick( event:MouseEvent):void

{

event.target.

}

s63.buttonMode = true;

xmlLoader:

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.addEventListener(Event.COMPLETE, showXML);

xmlLoader.load(new URLRequest("Talega.xml"));

function showXML(e:Event):void {

XML.ignoreWhitespace = true;

var bldg:XML = new XML(e.target.data);

var i:Number;

var myText:String = new String();

textField.multiline=true;

textField.wordWrap=true;

textField.text = myText;

            for (i=0; i < bldg.S11.length(); i++) {

                myText += bldg.S11.Title + "<br />";

                myText += "Square Footage: " + bldg.S11.SF + "<br />";

                myText += "Tenant: " + bldg.S11.Tenant + "<br />";

                myText += "Status: " + bldg.S11.Status + "<br />";

            }

            textField.htmlText = myText;

}

Thank you again. This is much appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2011 Apr 06, 2011
LATEST

Do you mean something like:

function onClick(e:MouseEvent):void {

      loadXML();

}

function loadXML():void {

     var xmlLoader:URLLoader = new URLLoader();

     xmlLoader.addEventListener(Event.COMPLETE, showXML);

     xmlLoader.load(new URLRequest("Talega.xml"));

}

function showXML(e:event){

     // process XML

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines