Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. import mx.utils.Delegate;
  2. var s:XMLSocket = new XMLSocket();
  3. s.onConnect = function(success:Boolean) {
  4. if(success) {
  5. trace('connected');
  6. s.send("<ping />");
  7. }
  8. else {
  9. trace('could not connect');
  10. }
  11. };
  12. s.onData = function(msg) {
  13. trace(msg);
  14. var myXml:XML = new XML(msg);
  15. if (myXml.firstChild.attributes.type == "you") {
  16. var you:Number = myXml.firstChild.attributes.id;
  17. setUpBall(you);
  18. }
  19. else if (myXml.firstChild.attributes.type == "move") {
  20. moveBall(myXml.firstChild.attributes.id, myXml.firstChild.attributes.x, myXml.firstChild.attributes.y, myXml.firstChild.attributes.xscale, myXml.firstChild.attributes.yscale);
  21. }
  22. };
  23. s.connect("localhost", 9999);
  24. //----------------------------
  25. var speed:Number = 4;
  26.  
  27. function setUpBall(you) {
  28. var you:MovieClip = this.attachMovie("Ball", "ball" + you, this.getNextHighestDepth());
  29. you._x = 275;
  30. you._y = 175;
  31. you.onEnterFrame = function() {
  32. if (Key.isDown(Key.LEFT)) {
  33. this._x -= speed;
  34. this._xscale = -100;
  35. }
  36. if (Key.isDown(Key.RIGHT)) {
  37. this._x += speed;
  38. this._xscale = 100;
  39. }
  40. if (Key.isDown(Key.UP)) {
  41. this._y -= speed;
  42. this._yscale = -100;
  43. }
  44. if (Key.isDown(Key.DOWN)) {
  45. this._y += speed;
  46. this._yscale = 100;
  47. }
  48. out = "<msg type='move' id='" + you + "' x='" + this._x + "' y='" + this._y + "' xscale='" + this._xscale + "' yscale='" + this._yscale + "' />\n";
  49. if (out != prev) {
  50. s.send(out);
  51. }
  52. prev = "<msg type='move' id='" + you + "' x='" + this._x + "' y='" + this._y + "' xscale='" + this._xscale + "' yscale='" + this._yscale + "' />\n";
  53. };
  54. }
  55.  
  56. function moveBall(id, xc, yx, xs, ys) {
  57. id._x = xc;
  58. id._y = yc;
  59. id._xscale = xs;
  60. id._yscale = ys;
  61. }
Add Comment
Please, Sign In to add comment