AS3 - Reading the first element from XML

advertisements

I loaded XML in AS3. In that XML, I make that flash will retrieving a value of an attribute and traced it. the output was:

test1,test2,test3,test4

But I want that flash will output only the first element from that output (test1 only). I searched in Google and I didn't find an answer.

Sample of my XML content :

<data>
    <myXML typesId="test1,test2,test3,test4"/>
</data>


You can extract the first word (test1) from the typesId parameter using String.substr() function :

var xml:XML = <data>
    <myXML typesId="test1,test2,test3,test4"/>
</data>;

var types:String = [email protected];

trace(types.substr(0, types.indexOf(',')));     // gives : test1

Hope that can help.