amv2: Implement flash.xml.XMLNode removeNode
This commit is contained in:
parent
445643fedb
commit
72965b3689
|
@ -60,9 +60,30 @@ package flash.xml
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeNode() : void
|
public function removeNode(): void {
|
||||||
{
|
if (parentNode) {
|
||||||
stub_method("flash.xml.XMLNode", "removeNode");
|
if (parentNode.firstChild === this) {
|
||||||
|
parentNode.firstChild = nextSibling;
|
||||||
|
}
|
||||||
|
if (parentNode.lastChild === this) {
|
||||||
|
parentNode.lastChild = previousSibling;
|
||||||
|
}
|
||||||
|
var index = parentNode.childNodes.indexOf(this);
|
||||||
|
if (index > -1) {
|
||||||
|
parentNode.childNodes.removeAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previousSibling) {
|
||||||
|
previousSibling.nextSibling = nextSibling;
|
||||||
|
}
|
||||||
|
if (nextSibling) {
|
||||||
|
nextSibling.previousSibling = previousSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentNode = null;
|
||||||
|
previousSibling = null;
|
||||||
|
nextSibling = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insertBefore(node: XMLNode, before: XMLNode = null): void {
|
public function insertBefore(node: XMLNode, before: XMLNode = null): void {
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package {
|
||||||
|
import flash.display.Sprite;
|
||||||
|
public class Test extends Sprite { }
|
||||||
|
}
|
||||||
|
|
||||||
|
import flash.xml.XMLDocument;
|
||||||
|
|
||||||
|
trace("///");
|
||||||
|
var doc = new XMLDocument('<parent><child hello="world">a single child</child></parent>');
|
||||||
|
trace("doc: " + doc);
|
||||||
|
var single = doc.firstChild.firstChild;
|
||||||
|
trace("single: " + single);
|
||||||
|
single.removeNode();
|
||||||
|
trace("/// After removal");
|
||||||
|
trace("doc: " + doc);
|
||||||
|
trace("single: " + single);
|
||||||
|
trace("single.parentNode: " + single.parentNode);
|
||||||
|
trace("single.nextSibling: " + single.nextSibling);
|
||||||
|
trace("single.previousSibling: " + single.previousSibling);
|
||||||
|
|
||||||
|
function test(index) {
|
||||||
|
var doc = new XMLDocument('<parent><first/><second/><last/></parent>')
|
||||||
|
trace("///")
|
||||||
|
trace("doc: " + doc);
|
||||||
|
var root = doc.firstChild;
|
||||||
|
var childNodes = root.childNodes;
|
||||||
|
var child = childNodes[index];
|
||||||
|
trace("root.childNodes[" + index + "]: " + child);
|
||||||
|
child.removeNode();
|
||||||
|
trace("/// After removal");
|
||||||
|
trace("doc: " + doc);
|
||||||
|
trace("child: " + child);
|
||||||
|
trace("child.parentNode: " + child.parentNode);
|
||||||
|
trace("child.nextSibling: " + child.nextSibling);
|
||||||
|
trace("child.previousSibling: " + child.previousSibling);
|
||||||
|
|
||||||
|
trace("root.firstChild: " + root.firstChild);
|
||||||
|
trace("root.lastChild: " + root.lastChild);
|
||||||
|
|
||||||
|
for (var i = 0; i < childNodes.length; i++) {
|
||||||
|
trace("childNodes[" + i + "]: " + childNodes[i]);
|
||||||
|
trace("childNodes[" + i + "].previousSibling: " + childNodes[i].previousSibling);
|
||||||
|
trace("childNodes[" + i + "].nextSibling: " + childNodes[i].nextSibling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test(0);
|
||||||
|
test(1);
|
||||||
|
test(2);
|
|
@ -0,0 +1,60 @@
|
||||||
|
///
|
||||||
|
doc: <parent><child hello="world">a single child</child></parent>
|
||||||
|
single: <child hello="world">a single child</child>
|
||||||
|
/// After removal
|
||||||
|
doc: <parent />
|
||||||
|
single: <child hello="world">a single child</child>
|
||||||
|
single.parentNode: null
|
||||||
|
single.nextSibling: null
|
||||||
|
single.previousSibling: null
|
||||||
|
///
|
||||||
|
doc: <parent><first /><second /><last /></parent>
|
||||||
|
root.childNodes[0]: <first />
|
||||||
|
/// After removal
|
||||||
|
doc: <parent><second /><last /></parent>
|
||||||
|
child: <first />
|
||||||
|
child.parentNode: null
|
||||||
|
child.nextSibling: null
|
||||||
|
child.previousSibling: null
|
||||||
|
root.firstChild: <second />
|
||||||
|
root.lastChild: <last />
|
||||||
|
childNodes[0]: <second />
|
||||||
|
childNodes[0].previousSibling: null
|
||||||
|
childNodes[0].nextSibling: <last />
|
||||||
|
childNodes[1]: <last />
|
||||||
|
childNodes[1].previousSibling: <second />
|
||||||
|
childNodes[1].nextSibling: null
|
||||||
|
///
|
||||||
|
doc: <parent><first /><second /><last /></parent>
|
||||||
|
root.childNodes[1]: <second />
|
||||||
|
/// After removal
|
||||||
|
doc: <parent><first /><last /></parent>
|
||||||
|
child: <second />
|
||||||
|
child.parentNode: null
|
||||||
|
child.nextSibling: null
|
||||||
|
child.previousSibling: null
|
||||||
|
root.firstChild: <first />
|
||||||
|
root.lastChild: <last />
|
||||||
|
childNodes[0]: <first />
|
||||||
|
childNodes[0].previousSibling: null
|
||||||
|
childNodes[0].nextSibling: <last />
|
||||||
|
childNodes[1]: <last />
|
||||||
|
childNodes[1].previousSibling: <first />
|
||||||
|
childNodes[1].nextSibling: null
|
||||||
|
///
|
||||||
|
doc: <parent><first /><second /><last /></parent>
|
||||||
|
root.childNodes[2]: <last />
|
||||||
|
/// After removal
|
||||||
|
doc: <parent><first /><second /></parent>
|
||||||
|
child: <last />
|
||||||
|
child.parentNode: null
|
||||||
|
child.nextSibling: null
|
||||||
|
child.previousSibling: null
|
||||||
|
root.firstChild: <first />
|
||||||
|
root.lastChild: <second />
|
||||||
|
childNodes[0]: <first />
|
||||||
|
childNodes[0].previousSibling: null
|
||||||
|
childNodes[0].nextSibling: <second />
|
||||||
|
childNodes[1]: <second />
|
||||||
|
childNodes[1].previousSibling: <first />
|
||||||
|
childNodes[1].nextSibling: null
|
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
num_frames = 1
|
Loading…
Reference in New Issue