플래시로 외부 파일 데이터를 가져오기 위한 웹서버와 통신하기 샘플 소스 코드입니다. 플래시 액션스크립트 초급자를 위해 학습용으로 부담없이 테스트할 수 있도록 만들었으므로 차근 차근 살펴 보시면 이해에 도움이 될 것이라 생각됩니다. XML 로 규격화된 자료 파일을 플래시에서 읽을 수 있다는 것은 자료에 근거하여 어플리케이션 처럼 동작하는 동적 플래시를 만들 수 있는 장점이 있습니다. 플래시로 XML 객체를 어떻게 다루는지 잘 익혀두시고 차후에 쓸만한 플래시 만드는 일에 잘 활용해보세요.

[product.xml]
<?xml version="1.0" encoding="euc-kr" ?>
<product>
    <item>
        <name>desktop</name>
        <price>380000</price>
        <total>10</total>
        <date>2008-10-01</date>
    </item>
    <item>
        <name>monitor</name>
        <price>270000</price>
        <total>5</total>
        <date>2008-10-04</date>
    </item>
    <item>
        <name>printer</name>
        <price>160000</price>
        <total>2</total>
        <date>2008-09-28</date>
    </item>
    <item>
        <name>notebook</name>
        <price>870000</price>
        <total>15</total>
        <date>2008-10-06</date>
    </item>
    <item>
        <name>mouse</name>
        <price>12000</price>
        <total>20</total>
        <date>2008-09-20</date>
    </item>
</product>


[product_xml.fla]
System.useCodepage = true;
function product_loader() {
    var product_xml = this.firstChild.childNodes;
    var product_len = product_xml.length;
    var item_xml = product_xml[0].childNodes;
    var item_len = item_xml.length;
    var name_xml = item_xml[0].childNodes;
    var name_len = name_xml.length;
    tf_textarea.text += '[xml file tester]\n';
    tf_textarea.text += '01: ' + product_len + "\n";
    tf_textarea.text += '02: ' + product_xml + "\n";
    tf_textarea.text += '03: ' + item_len + "\n";
    tf_textarea.text += '04: ' + item_xml + "\n";
    tf_textarea.text += '05: ' + name_len + "\n";
    tf_textarea.text += '06: ' + name_xml + "\n";
    tf_textarea.text += '\n';
    tf_textarea.text += '07: ' + item_xml[0].nodeName + "\n";
    tf_textarea.text += '08: ' + item_xml[0].firstChild.nodeValue + "\n";
    tf_textarea.text += '07: ' + item_xml[1].nodeName + "\n";
    tf_textarea.text += '08: ' + item_xml[1].firstChild.nodeValue + "\n";
    tf_textarea.text += '09: ' + item_xml[2].nodeName + "\n";
    tf_textarea.text += '10: ' + item_xml[2].firstChild.nodeValue + "\n";
    tf_textarea.text += '11: ' + item_xml[3].nodeName + "\n";
    tf_textarea.text += '12: ' + item_xml[3].firstChild.nodeValue + "\n";
    tf_textarea.text += '\n';
    textarea += '13: ' + product_xml[3].childNodes[0].nodeName + "\n";
    textarea += '14: ' + product_xml[3].childNodes[0].firstChild.nodeValue + "\n";
    textarea += '15: ' + product_xml[3].childNodes[1].nodeName + "\n";
    textarea += '16: ' + product_xml[3].childNodes[1].firstChild.nodeValue + "\n";
    textarea += '17: ' + product_xml[3].childNodes[2].nodeName + "\n";
    textarea += '18: ' + product_xml[3].childNodes[2].firstChild.nodeValue + "\n";
    textarea += '19: ' + product_xml[3].childNodes[3].nodeName + "\n";
    textarea += '20: ' + product_xml[3].childNodes[3].firstChild.nodeValue + "\n";
    tf_textarea.text += '\n';
    textarea += '21: ' + product_xml[3].firstChild.nextSibling.nodeName + "\n";
    textarea += '22: ' + product_xml[3].firstChild.nextSibling.nextSibling.nodeName + "\n";
    /*
    trace('product len = ' + product_len);
    trace('product xml = ' + product_xml);
    trace('item len = ' + item_len);
    trace('item xml = ' + item_xml);
    trace('name len = ' + name_len);
    trace('name xml = ' + name_xml);
    */
}
my_xml = new XML();
my_xml.onLoad = product_loader;
my_xml.ignoreWhite = true;
my_xml.load("product.xml");

[product_xml.swf]
 

[product_xml.html]
<embed
src="http://www.hompydesign.com/flash/sample/product_xml.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="520" height="420" base="http://www.hompydesign.com/flash/sample/"></embed>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info
이올린에 북마크하기(0) 이올린에 추천하기(0)

트랙백 주소 :: http://hompy.info/trackback/512