XMLをループで見る

by h_sakurai forked from XML (diff: 23)
♥0 | Line 34 | Modified 2010-12-13 15:55:16 | MIT License
play

ActionScript3 source code

/**
 * Copyright h_sakurai ( http://wonderfl.net/user/h_sakurai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hSf5
 */

// forked from h_sakurai's XML
// forked from h_sakurai's 連想配列2
// forked from h_sakurai's 連想配列
// forked from h_sakurai's for each
// forked from h_sakurai's 配列
// forked from h_sakurai's while文
// forked from h_sakurai's switch文
// forked from h_sakurai's if文
// forked from h_sakurai's forループ
// forked from h_sakurai's テキストフィールド
package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.xml.XMLNode;
    
    
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var tf:TextField = new TextField();// テキストフィールド(文字列を表示するもの)を作成する
            var str:String = "";// 文字列変数
            var xml:XML = <root>
                <data>aiu</data>
                <data>eo</data>
                <data>ao</data>
            </root>; // xmlを直で書けるぞ。
            var i:int;
            str += "*xml.data\n";
            str += xml.data + "\n";
            
            str += "*for\n";
            var s:String;
            for (s in xml.data) {
                str += xml.data[s]+"\n";
            }
            
            tf.text = str;
            tf.x = 100;// x座標を100にする
            tf.y = 100;// y座標を100にする
            tf.width = 200;// 幅を指定する
            tf.height = 200;// 高さを指定する
            addChild(tf);// 画面にテキストフィールドを張り付ける

            tf.appendText("*for each\n"); // appendTextでtextfieldに直接値を追加できて+=より速いです。
            for each(s in xml.data) {
               tf.appendText(s+"\n");
            }

        }
    }
}

Forked