创建时钟系统,需要从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;
}
}
答案 0 :(得分: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
}