Posts Tagged “XML”

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 »

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 »

Dynamically listing the properties of a class is pretty cool and useful. There are many things you could do by generating a list of existing properties. One example is you can make your class instances represent themselves dynamically in a custom format of your choosing. Like how "toString()" is use with the Array class or how Point is represented when toString() is called from it. Going further, listing current properties could be used to save the current values of the class as a "save point".

In the Flex framework, there is ObjectUtil.getClassInfo().properties, but I feel is more useful to just use the XML returned from the describeType method. I like using decribeType for both plain AS3 or when using the Flex framework because its accessible in both.
Since the return of describeType is XML I have more options with E4X filtering/Regular Expressions, than using getClassInfo(). With describeType I can get info on methods as well but to keep things simple I'm only talking about accessor properties in this post. Using the "listProperties" function, I am listing the properties between 3 different classes. This is a function I wrote to show how you can make your own way to use the XML of decribeType.

In the example SWF below, there are 3 classes under inspection. The Helicopter class is a custom class extending Sprite. By setting the parameters of listProperties you can list the properties of Helicopter, or all of the properties it has by being subclassed from Sprite. The other classes are a TextField and a Sprite class. Changing the options lists a different set of properties based on type of Class of properties listed and what class its properties are declared by.

Get Adobe Flash player


Read the rest of this entry »

Vote in HexoSearch

Comments 1 Comment »

Thanks for visiting www.keith-hair.net