03-25-2011 03:18 PM
I'm developing an ActionScript 3 app for Playbook.
I have an XML file with some texts. One of them is a big string. I want to show it in the following Label:
var label32:Label = new Label(); label32.setPosition(5, 5); label32.setSize(100, 100); label32.multiline = true; label32.autoSize = TextFieldAutoSize.LEFT; label32.embedFonts = true; label32.textField.antiAliasType = AntiAliasType.ADVANCED; label32.textField.sharpness = 1; label32.textField.thickness = 25; label32.textField.gridFitType = GridFitType.PIXEL; label32.format = instrucTextFormat; label32.text = loadString(4, getUserLanguage());
I have added '\n' inside the string to split it, but it doesn't work.
If I use html, can I add HTML tags inside an XML file?
Any advice?
03-25-2011 03:49 PM - edited 03-25-2011 03:52 PM
Since you have a the label to multline = true it will show on multiple lines when you set the width property to a static value. You shouldn't need to put \n or use html.
but you should be able to put break tags in the xml just make sure to use the CDATA[ "html" ] when you do it if you choose to use html
03-25-2011 05:55 PM
03-25-2011 10:44 PM
L7 is right. The text will wrap. Still, if you are looking to break the line at a specific point using the new line character you should be able to.
label.text ="line1\nline 2"; will in fact yield:
line1
line2
If your text is not wrapping or you still fail to get multiple lines using \n I suggest you at least trace the string to make sure its correct. When tracing it, you should see multiple lines if using \n. If you do not, then check your string.
03-26-2011 01:43 AM
I've tried all of yours solutions, and it doesn't work for me.
Above, I put the code that it's not working. Multiline doesn't work here and '\n' caracter either.
I'm using htmlText with <BR> and works fine.
03-26-2011 12:20 PM
glad htmlText is doing the trick for you. You mention your code sample, but there's no way for us to know what your loadString() function is returning which is why I suggested tracing it. If you're content with how it works now then you're all set.
Just out of curiosity, did you ever trace the output of that function? If so, did you get the line breaks on the console window?
03-26-2011 12:23 PM
Suppose that loadString() returns a String like this:
"function is returning which is why I suggested tracing it. If you're content with how it works now then you're all set. Just out of curiosity, did you ever trace the output of that function? If so, did you get the line breaks on the console window?"
03-26-2011 12:31 PM
ok, so where would you insert the '\n' and how were you doing it?
03-26-2011 12:59 PM
Don't worry, it's working with htmlText.
I'm using \n like this:
function is returning which is why I suggested tracing it. If you're content with how it works now then you're all set.\nJust out of curiosity, did you ever trace the output of that function? If so, did you get the line breaks on the console window?
I've added a \n at the beginning of line 2.