Skip to main content
Known Participant
September 20, 2010
Answered

AS3 help?

  • September 20, 2010
  • 2 replies
  • 1109 views

I have XML file with data and I am loading this to text filed.

How can check the length of values (like value1, value2…)? And

The text field has to accept only 20 chars from each value.  If it’s more than 20 chars then it should remove (delete) 21, 22 …. chars.

XML code:

<?xml version="1.0" encoding="utf-8" ?>

<data>

<Header1>        

<option>

<value1> Adobe Photoshop</value1>

<value2> Adobe Flash Professional </value2>

<value3> Adobe Acrobat Professional </value3>

<value4> Adobe Premiere Pro </value1>

</option>

</Header1>

</data>

Please help me!

Thanks

jafy

This topic has been closed for replies.
Correct answer

You can use string.substr(start, length) to do what you need.

ie:

myTextField.text = myValue.substr(0, 20);

Will place the first 20 chars of myValue into the field.

2 replies

Correct answer
September 20, 2010

You can use string.substr(start, length) to do what you need.

ie:

myTextField.text = myValue.substr(0, 20);

Will place the first 20 chars of myValue into the field.

Jafy78Author
Known Participant
September 21, 2010

Thank a lot Ned Murphy and dmennenoh,


if i have xml like this

<value2><![CDATA[<a href="http://www.google.com">Google</a><br>]]></value2>

then what i have to do?

Thanks,

jafy

Ned Murphy
Legend
September 21, 2010

You might be better off writing the xml differently, so that it contains two parameters for each node... the link and the text.  Otherwise you will have to write a bit of code to isolate the two if you want to have the entire link intact but the text reduced to 20 characters at most.

Ned Murphy
Legend
September 20, 2010

Look at the String class and the properties and methods that support it.  You can use the length property (String.length) to determine how many characters are in the String.  And you can use the slice() or substr() method to capture a particular section of the String for appending to the TextField.