- 忘了Excel中。
- 實際上,這對於XML來說並不難。只是一個簡單的例子。
var X:XML =
<root>
<point x="0" y="0" />
<point x="100" y="100" />
<point x="10" y="50" />
<point x="200" y="10" />
<point x="45" y="45" />
<point x="35" y="100" />
</root>;
這是很基本的東西,但它展示瞭如何通過XML節點的列表以及如何訪問它們的屬性瀏覽。
drawZigzag(X);
function drawZigzag(source:XML):void
{
// Get a list of points.
var aList:XMLList = source.child("point");
// Get the starting point.
var aNode:XML = aList[0];
var anX:Number = [email protected];
var anY:Number = [email protected];
// Start drawing.
graphics.lineStyle(0, 0x000000);
graphics.moveTo(anX, anY);
for (var i:int = 1; i < aList.length(); i++)
{
// Get the next coordinates.
aNode = aList[i];
anX = [email protected];
anY = [email protected];
// Draw the line.
graphics.lineTo(anX, anY);
}
}
現在,如果你想它是一個外部文件。這也是非常基本的,沒有錯誤處理和東西,但應該工作,如果你準備好所有的事情。
// I hope the following is self-explanatory.
var xmlRequest:URLRequest = new URLRequest("your.xml");
var dataLoader:URLLoader = new URLLoader;
// Loading is asynchronous so you need to listen for a relevant event.
dataLoader.addEventListener(Event.COMPLETE, onFile);
dataLoader.load(xmlRequest);
function onFile(e:Event):void
{
// Of course, your file MUST be a valid XML.
var X:XML = new XML(dataLoader.data);
// The data are ready, you can call the drawing routine now.
drawZigzag(X);
}
非常感謝Organis,這非常棒。我需要一段時間才能掌握它。祝一切順利 – Rich