Код
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
public class Main extends Sprite
{
// -----------------------------------------------------------------------------------------------------
private var xmldata:XML;
private var loader:URLLoader;
private var massNames:Array=[];
private var txt:TextField;
// -----------------------------------------------------------------------------------------------------
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
// -----------------------------------------------------------------------------------------------------
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
loader = new URLLoader(new URLRequest("../src/data.xml"))
loader.addEventListener(Event.COMPLETE, onXMLLoaded)
txt = new TextField()
txt.width = stage.stageWidth;
txt.height = stage.stageHeight;
addChild(txt);
txt.text = massNames.join('\n');
}
// -----------------------------------------------------------------------------------------------------
private function onXMLLoaded(e:Event):void
{
xmldata = XML(loader.data);
parseXML(xmldata);
}
// -----------------------------------------------------------------------------------------------------
private function parseXML(xd:XML):void
{
for each (var name:XML in xd.products)
{
massNames.push(name);
}
}
// -----------------------------------------------------------------------------------------------------
}
}
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
public class Main extends Sprite
{
// -----------------------------------------------------------------------------------------------------
private var xmldata:XML;
private var loader:URLLoader;
private var massNames:Array=[];
private var txt:TextField;
// -----------------------------------------------------------------------------------------------------
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
// -----------------------------------------------------------------------------------------------------
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
loader = new URLLoader(new URLRequest("../src/data.xml"))
loader.addEventListener(Event.COMPLETE, onXMLLoaded)
txt = new TextField()
txt.width = stage.stageWidth;
txt.height = stage.stageHeight;
addChild(txt);
txt.text = massNames.join('\n');
}
// -----------------------------------------------------------------------------------------------------
private function onXMLLoaded(e:Event):void
{
xmldata = XML(loader.data);
parseXML(xmldata);
}
// -----------------------------------------------------------------------------------------------------
private function parseXML(xd:XML):void
{
for each (var name:XML in xd.products)
{
massNames.push(name);
}
}
// -----------------------------------------------------------------------------------------------------
}
}
а так же есть xml:
Код
<?xml version="1.0" encoding="windows-1251" ?>
<products>
<product id="1">
<name>продукт 1</name>
<cost>9.99</cost>
</product>
<product id="2">
<name>продукт 2</name>
<cost>5.99</cost>
</product>
<product id="3">
<name>продукт 3</name>
<cost>1.00</cost>
</product>
<product id="4">
<name>продукт 4</name>
<cost>159.99</cost>
</product>
<product id="5">
<name>продукт 5</name>
<cost>11.5</cost>
</product>
</products>
<products>
<product id="1">
<name>продукт 1</name>
<cost>9.99</cost>
</product>
<product id="2">
<name>продукт 2</name>
<cost>5.99</cost>
</product>
<product id="3">
<name>продукт 3</name>
<cost>1.00</cost>
</product>
<product id="4">
<name>продукт 4</name>
<cost>159.99</cost>
</product>
<product id="5">
<name>продукт 5</name>
<cost>11.5</cost>
</product>
</products>
что я не так делаю? почему не выводится список продукт 1 - продукт 5 в текстовое поле?