home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Dual.swf / scripts / __Packages / mochi / MochiScores.as next >
Encoding:
Text File  |  2008-09-03  |  4.3 KB  |  158 lines

  1. class mochi.MochiScores
  2. {
  3.    static var boardID;
  4.    static var onClose;
  5.    static var onError;
  6.    function MochiScores()
  7.    {
  8.    }
  9.    static function setBoardID(boardID)
  10.    {
  11.       mochi.MochiScores.boardID = boardID;
  12.       mochi.MochiServices.send("scores_setBoardID",{boardID:boardID});
  13.    }
  14.    static function showLeaderboard(options)
  15.    {
  16.       if(options.clip != null)
  17.       {
  18.          if(options.clip != mochi.MochiServices.clip || mochi.MochiServices.childClip._target == undefined)
  19.          {
  20.             mochi.MochiServices.disconnect();
  21.             mochi.MochiServices.connect(mochi.MochiServices.id,options.clip);
  22.          }
  23.          delete options.clip;
  24.       }
  25.       if(options.name != null)
  26.       {
  27.          if(typeof options.name == "object")
  28.          {
  29.             if(options.name.text != undefined)
  30.             {
  31.                options.name = options.name.text;
  32.             }
  33.          }
  34.       }
  35.       if(options.score != null)
  36.       {
  37.          if(typeof options.score == "object")
  38.          {
  39.             if(options.score.text != undefined)
  40.             {
  41.                options.score = options.score.text;
  42.             }
  43.          }
  44.       }
  45.       if(options.onDisplay != null)
  46.       {
  47.          options.onDisplay();
  48.       }
  49.       else
  50.       {
  51.          mochi.MochiServices.clip.stop();
  52.       }
  53.       if(options.onClose != null)
  54.       {
  55.          mochi.MochiScores.onClose = options.onClose;
  56.       }
  57.       else
  58.       {
  59.          mochi.MochiScores.onClose = function()
  60.          {
  61.             mochi.MochiServices.clip.play();
  62.          };
  63.       }
  64.       if(options.onError != null)
  65.       {
  66.          mochi.MochiScores.onError = options.onError;
  67.       }
  68.       else
  69.       {
  70.          mochi.MochiScores.onError = mochi.MochiScores.onClose;
  71.       }
  72.       if(options.boardID == null)
  73.       {
  74.          if(mochi.MochiScores.boardID != null)
  75.          {
  76.             options.boardID = mochi.MochiScores.boardID;
  77.          }
  78.       }
  79.       mochi.MochiServices.send("scores_showLeaderboard",{options:options},null,mochi.MochiScores.doClose);
  80.    }
  81.    static function closeLeaderboard()
  82.    {
  83.       mochi.MochiServices.send("scores_closeLeaderboard");
  84.    }
  85.    static function getPlayerInfo(callbackObj, callbackMethod)
  86.    {
  87.       mochi.MochiServices.send("scores_getPlayerInfo",null,callbackObj,callbackMethod);
  88.    }
  89.    static function submit(score, name, callbackObj, callbackMethod)
  90.    {
  91.       mochi.MochiServices.send("scores_submit",{score:score,name:name},callbackObj,callbackMethod);
  92.    }
  93.    static function requestList(callbackObj, callbackMethod)
  94.    {
  95.       mochi.MochiServices.send("scores_requestList",null,callbackObj,callbackMethod);
  96.    }
  97.    static function scoresArrayToObjects(scores)
  98.    {
  99.       var _loc5_ = {};
  100.       var _loc1_ = undefined;
  101.       var _loc4_ = undefined;
  102.       var _loc2_ = undefined;
  103.       var _loc6_ = undefined;
  104.       for(var _loc8_ in scores)
  105.       {
  106.          if(typeof scores[_loc8_] == "object")
  107.          {
  108.             if(scores[_loc8_].cols != null && scores[_loc8_].rows != null)
  109.             {
  110.                _loc5_[_loc8_] = [];
  111.                _loc2_ = scores[_loc8_];
  112.                _loc4_ = 0;
  113.                while(_loc4_ < _loc2_.rows.length)
  114.                {
  115.                   _loc6_ = {};
  116.                   _loc1_ = 0;
  117.                   while(_loc1_ < _loc2_.cols.length)
  118.                   {
  119.                      _loc6_[_loc2_.cols[_loc1_]] = _loc2_.rows[_loc4_][_loc1_];
  120.                      _loc1_ = _loc1_ + 1;
  121.                   }
  122.                   _loc5_[_loc8_].push(_loc6_);
  123.                   _loc4_ = _loc4_ + 1;
  124.                }
  125.             }
  126.             else
  127.             {
  128.                _loc5_[_loc8_] = {};
  129.                for(var _loc7_ in scores[_loc8_])
  130.                {
  131.                   _loc5_[_loc8_][_loc7_] = scores[_loc8_][_loc7_];
  132.                }
  133.             }
  134.          }
  135.          else
  136.          {
  137.             _loc5_[_loc8_] = scores[_loc8_];
  138.          }
  139.       }
  140.       return _loc5_;
  141.    }
  142.    static function doClose(args)
  143.    {
  144.       if(args.error == true)
  145.       {
  146.          if(args.errorCode == undefined)
  147.          {
  148.             args.errorCode = "IOError";
  149.          }
  150.          mochi.MochiScores.onError.apply(null,[args.errorCode]);
  151.       }
  152.       else
  153.       {
  154.          mochi.MochiScores.onClose.apply();
  155.       }
  156.    }
  157. }
  158.