I think this problem is caused by name confilct with
xml method/property name.
If you choose 'copy' (XML has XML.copy()) for another
local variable name, the problem occurres.
You can hide XML method name with its child tag name.
So I guess the name look up in e4x notation would go like:
Child Tag Name > XML Method Name > Other Variables In The Code
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lTh6
*/
// forked from tarotarorg's XML 属性抜き出し実験
/**
* I think this problem is caused by name confilct with
* xml method/property name.
* If you choose 'copy' (XML has XML.copy()) for another
* local variable name, the problem occurres.
* You can hide XML method name with its child tag name.
*
* So I guess the name look up in e4x notation would go like:
* Child Tag Name > XML Method Name > Other Variables In The Code
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var xml:XML =
<tests>
<test id="1">あ</test>
<test id="2">い</test>
<test id="3"><name>3</name></test>
<test id="4"><copy>4</copy></test>
</tests>;
public function FlashTest() {
// write as3 code here..
var test1:XML = xml.test.(@id=="1")[0];
var str2:String = "2";
var test2:XML = getXML(str2) as XML;
var test3:XML = getXML2(str2) as XML;
var test4:XML = getXML3(str2) as XML;
var txt:TextField = new TextField();
txt.appendText(test1 + "\n");
txt.appendText(test2 + "\n");
txt.appendText(test3 + "\n");
txt.appendText(test4 + "\n");
txt.width = txt.textWidth + 4;
txt.height = txt.textHeight + 4;
addChild(txt);
}
private function getXML(name:String):Object {
return xml.test.(@id==name)[0];
}
private function getXML2(n:String):Object {
return xml.test.(@id==n)[0];
}
private function getXML3(copy:String):Object {
return xml.test.(@id==copy)[0];
}
}
}