开发者

Linking a movieclip on the stage to a database entity, Flash AS3 PHP MySQL

Does anybody now how i can link an entity on the stage to a database entity in Flash.

Im doing a seating plan and would like to query the database to 开发者_高级运维see if that seat is available or not. If not then make it un-selectable.

Do i need to give every seat an instance name relating to a row in the DB?

I'll be using PHP, MySQL / XML i think, the rest of my app is built in codeigniter if this sheds any light on the matter for anyone.

any help much appreciated, Thanks!


It's pretty straight forward actually. In your Flash, have a Seat class, which load from your XML (would recommend AMF much nicer).

Assuming XML looking like this:

<seatMap>
    <seat available="0" row="23" alley="I"/>
    <seat available="1" row="23" alley="J"/>
    <seat available="0" row="23" alley="K"/>
</seatMap>

Main class looking like this:

package { import 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);
        }
    }
}

}

Your seat class should look somewhat like this:

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 = (seatDef.@available !== null)? seatDef.@available : false;
                this._row = seatDef.@row;
                this._alley = seatDef.@alley;

                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
        }
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜