Archive for the “XML” Category

String'n together combos isn't always as fun as doing them in a fighting videogame.

If you write script that has a lot String content mixed with variables, I'm sure you're doing a lot of heavy concatenation.
Building string combos with quotes and apostrophes sprinkled all over a script gets confusing. The way I like to keep this confusion to a minimum is to write my static markup separately. This allows me to make sure it shows up as intended. Then I concatenate my variables in all the places that need to have dynamic content.

Taking static markup or script and wrapping quotes around every line is a chore so I made this Concatenation Tool to help with that.

Currently I've only made this support languages I'm using mostly. If I have to use a new language I'd just add it in.
Read the rest of this entry »

Vote in HexoSearch

Comments 2 Comments »

I wanted to create a list of Strings from only the attributes of an XMLList, and I wanted them separated with carriage returns.

The "toXMLString()" method does this automatically on attributes.
Attributes are typed as XMLList.

 
var myXmlList:XMLList=XMLList(<B><P name="Orange"/><P name="Grape"/><P name="Pear"/></B>).P;
trace(myXmlList..@name.toXMLString());
//Outputs multiple values of all "name" attributes separated with carriage returns automatically.
Orange
Grape
Pear
 

Putting the values of an XMLList as an Array might be useful also.

Being separated by carriage returns makes it easy to convert to an Array by using the String "split" method.

Wrap this into a function for easy use.

 
function xmllistToArray(list:XMLList):Array
             {
                 return list.toXMLString().split("\n");
             }
 

Vote in HexoSearch

Comments 1 Comment »

Recently I was working with an XMLList variable and I wanted to add a new XML node to an XMLList.
My first thought was to just use the "appendChild" method as you would with an XML object.
I wasn't really aware of how to do this, and I did not see an XMLList method listed for appending childs in the AS3 documentation.
So I "googled" the term "E4X specification" and read about the "compound assignment operator +=".
Wow using "+=" was really simple.

In the example below I was trying to add a new PAGE node to the existing "PAGE" XMLList....







Before when I used "appendChild". Error!
Even if my XMLList had one child, it would not be the result I wanted.

 
var doc:XML=
<BOOK>
	<PAGE />
	<PAGE />
	<PAGE />
</BOOK>;
 
trace("\nOriginal...");
trace(doc.toXMLString());
doc.PAGE.appendChild(<PAGE />);
trace("\nChanges...");
trace(doc.toXMLString());
 
\\Trace Output:
Original...
<BOOK>
  <PAGE/>
  <PAGE/>
  <PAGE/>
</BOOK>
TypeError: Error #1086: The appendChild method only works on lists containing one item.
	at XMLList/http://adobe.com/AS3/2006/builtin::appendChild()
	at Untitled_fla::MainTimeline/Untitled_fla::frame1()
 







Using the compound assignment operator "+=" gives the result I was looking for. The new PAGE node is added to the XMLList.

 
var doc:XML=
<BOOK>
	<PAGE />
	<PAGE />
	<PAGE />
</BOOK>;
 
trace("\nOriginal...");
trace(doc.toXMLString());
doc.PAGE+=<PAGE />; //doc.PAGE=doc.PAGE+<PAGE />; works just as well.
trace("\nChanges...");
trace(doc.toXMLString());
 
\\Trace Output:
Original...
<BOOK>
  <PAGE/>
  <PAGE/>
  <PAGE/>
</BOOK>
 
Changes...
<BOOK>
  <PAGE/>
  <PAGE/>
  <PAGE/>
  <PAGE/>
</BOOK>
 
Vote in HexoSearch

Comments 2 Comments »

Thanks for visiting www.keith-hair.net