實際上它非常簡單。 在你的Flash中,有一個Seat類,從你的XML中加載(會推薦AMF更好)。
假設XML看起來像這樣:
<seatMap>
<seat available="0" row="23" alley="I"/>
<seat available="1" row="23" alley="J"/>
<seat available="0" row="23" alley="K"/>
</seatMap>
Main類看起來像這樣:
包{ 進口flash.display.Sprite; import flash.events.Event;
public class Main extends Sprite
{
public function Main() {
//Code to load XML
}
public function onXMLLoaded(e:Event):void {
var seatMap:XML = new XML(e.target.data);
for each(var seat:XML in seatMap.seat) {
var mySeat:Seat = new Seat(seat);
//Do magic to place seat on stage
this.addChild(mySeat);
}
}
}
}
您的座位類應該看起來有點像這樣:
package{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Seat extends MovieClip
{
private var _isAvailable:Boolean;
private var _row:int;
private var _alley:String;
public function Seat(seatDef:XML) {
this._isAvailable = ([email protected] !== null)? [email protected] : false;
this._row = [email protected];
this._alley = [email protected];
this._bindListeners();
}
private function _bindListeners():void {
if (this._isAvailable) {
this.addEventListener(MouseEvent.MOUSE_DOWN, this.onClick);
}
//blah
}
public function onClick(e:MouseEvent):void {
//do magic
}
}
}
哇人,感謝這麼多...的theres相當多,我從那裏得到的,生病給它去! – Mark 2011-02-01 17:22:59