0

创建时钟系统,需要从xml访问数据。数据中的元素决定了建筑的颜色。需要帮助将 xml 中的数据与界面中的对象链接并定位它们。到目前为止,我已经能够提取数据,但不知道如何将这两者联系起来以定位它们。我才走到这一步。

import com.greensock.loading.*;
import com.greensock.loading.display.*;
import com.greensock.events.LoaderEvent;
import flash.events.Event; 
import flash.net.URLLoader; 


var xmlLoader:URLLoader=new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);

var xmlData:XMLList=new XMLList();
xmlLoader.load(new URLRequest("xmldata.xml"));

function loadXML(e:Event):void
{
    var i:int;
    xmlData = new XMLList(e.target.data);
    var theDots = xmlData.dots;
    var posx = xmlData.dots.posx;
    var posy = xmlData.dots.posy;
    for ( i=0; i<theDots.length(); i++ )
    {
        var dot_name = theDots[i].name;
        var pos_x = theDots[i].posx;
        var pos_y = theDots[i].posy;

        var mc:MovieClip = new theDot;
        var pos_x:Point X = new x;
        var pos_y:Point Y = new y;  
    }

}
4

1 回答 1

0

您必须设计您的TheDot类和所有其他简单类以接受构造函数中的属性,可能具有默认值,或者为它们提供函数以接受可能批量的属性,例如为建筑物着色将启动图形重新创建。一个例子:

public class TheHouse extends Sprite {
    private var fillColor:uint; // with alpha
    private var lineColor:uint;
    private var lineThickness:Number;
    private function drawHouse():void {
        // drawing house
        this.graphics.clear();
        this.graphics.lineStyle(lineThickness,(lineColor & 0xffffff),
            Number(lineColor>>>24)/255); // alpha is 0..1
        this.graphics.beginFill((fillColor&0xffffff),
            Number(fillColor>>>24)/255);
        this.graphics.circle(0,0,20); // *le perfectly drawn house code
        // actually here go graphics commands to draw a house via lines/curves
        this.graphics.endFill();
    }
    public function TheHouse() {
        lineColor=0xff000000;
        fillColor=0xffffffff;
        lineThickness=1.0;
        drawHouse();
    }
    public function set outlineColor(value:uint):void {
        if (lineColor==value) return;
        lineColor=value;
        drawHouse();
    } 
    // similarly do other setters
}
于 2013-03-20T08:55:33.000 回答