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>
Here is some Flash Builder script that does basic text search functionality.
It will find the index of the search and scroll a TextArea component to the String.
I'm using "indexOf" and "lastIndexOf" to perform the next and previous searches. I'd like to use Regular Expressions to find the next and previous occurrences in my search, but did not figure that out or know if it's possible to apply it for this.
If anyone knows a faster way let me know.