Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mx.utils.Delegate;
- var s:XMLSocket = new XMLSocket();
- s.onConnect = function(success:Boolean) {
- if(success) {
- trace('connected');
- s.send("<ping />");
- }
- else {
- trace('could not connect');
- }
- };
- s.onData = function(msg) {
- trace(msg);
- var myXml:XML = new XML(msg);
- if (myXml.firstChild.attributes.type == "you") {
- var you:Number = myXml.firstChild.attributes.id;
- setUpBall(you);
- }
- else if (myXml.firstChild.attributes.type == "move") {
- moveBall(myXml.firstChild.attributes.id, myXml.firstChild.attributes.x, myXml.firstChild.attributes.y, myXml.firstChild.attributes.xscale, myXml.firstChild.attributes.yscale);
- }
- };
- s.connect("localhost", 9999);
- //----------------------------
- var speed:Number = 4;
- function setUpBall(you) {
- var you:MovieClip = this.attachMovie("Ball", "ball" + you, this.getNextHighestDepth());
- you._x = 275;
- you._y = 175;
- you.onEnterFrame = function() {
- if (Key.isDown(Key.LEFT)) {
- this._x -= speed;
- this._xscale = -100;
- }
- if (Key.isDown(Key.RIGHT)) {
- this._x += speed;
- this._xscale = 100;
- }
- if (Key.isDown(Key.UP)) {
- this._y -= speed;
- this._yscale = -100;
- }
- if (Key.isDown(Key.DOWN)) {
- this._y += speed;
- this._yscale = 100;
- }
- out = "<msg type='move' id='" + you + "' x='" + this._x + "' y='" + this._y + "' xscale='" + this._xscale + "' yscale='" + this._yscale + "' />\n";
- if (out != prev) {
- s.send(out);
- }
- prev = "<msg type='move' id='" + you + "' x='" + this._x + "' y='" + this._y + "' xscale='" + this._xscale + "' yscale='" + this._yscale + "' />\n";
- };
- }
- function moveBall(id, xc, yx, xs, ys) {
- id._x = xc;
- id._y = yc;
- id._xscale = xs;
- id._yscale = ys;
- }
Add Comment
Please, Sign In to add comment