In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

XML 属性抜き出し実験

1.XMLをメンバ変数として定義する
2.XML内の特定の要素を、属性の値をキーにして引き出す関数を作る。今回は「id」を使う、getXMLを定義
3.関数getXML煮引数を渡しても、いつもnull


と思ったら、原因は引数名が「name」だったことらしい。意味が分からん。
Get Adobe Flash player
by tarotarorg 05 Jun 2011
/**
 * Copyright tarotarorg ( http://wonderfl.net/user/tarotarorg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/aRDe
 */

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>
       </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 txt:TextField = new TextField();
            txt.width = 300;
            txt.height = 100;
            txt.appendText(test1 + "\n");
            txt.appendText(test2 + "\n");
            txt.appendText(test3 + "\n");
            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];
        }
    }
}