home *** CD-ROM | disk | FTP | other *** search
/ Champak 54 / Vol 54.iso / games / turttleo.swf / scripts / __Packages / Helper.as < prev    next >
Encoding:
Text File  |  2007-10-01  |  6.1 KB  |  244 lines

  1. class Helper
  2. {
  3.    static var _Music;
  4.    static var _Music_name;
  5.    static var OnMusicLoaded;
  6.    static var _get_it_url;
  7.    static var _get_it_target;
  8.    static var COMPILING_NOADS = true;
  9.    static var DEBUG = false;
  10.    static var DEBUG2 = false;
  11.    static var DEBUG_MAP = false;
  12.    static var SKIP_INTRO = false;
  13.    static var SKIP_MENU = false;
  14.    static var SKIP_TIPS = false;
  15.    static var TIPS_BY_EVENT = false;
  16.    static var SKIP_MUSIC = false;
  17.    static var PlayerName = "";
  18.    static var SoundVolume = 100;
  19.    static var _MusicVolume = 100;
  20.    static var _Music_playing = false;
  21.    static var MusicEnabled = true;
  22.    function Helper()
  23.    {
  24.    }
  25.    static function get isMusicLoaded()
  26.    {
  27.       return Helper._Music != undefined && Helper._Music.getBytesTotal() == Helper._Music.getBytesLoaded();
  28.    }
  29.    static function get isMusicPlaying()
  30.    {
  31.       return Helper._Music_playing;
  32.    }
  33.    static function get Music()
  34.    {
  35.       return Helper._Music;
  36.    }
  37.    static function set Music(val)
  38.    {
  39.       Helper._Music = val;
  40.    }
  41.    static function PlaySound(name, loop)
  42.    {
  43.       var _loc1_ = new Sound();
  44.       _loc1_.attachSound(name);
  45.       _loc1_.setVolume(Helper.SoundVolume);
  46.       _loc1_.start(0,loop);
  47.    }
  48.    static function PlayMusic(name)
  49.    {
  50.       if(Helper.SKIP_MUSIC)
  51.       {
  52.          return undefined;
  53.       }
  54.       if(!Helper.MusicEnabled)
  55.       {
  56.          return undefined;
  57.       }
  58.       if(name == undefined)
  59.       {
  60.          name = Helper._Music_name;
  61.       }
  62.       else
  63.       {
  64.          Helper._Music_name = name;
  65.       }
  66.       Tracer.info("Play music: " + Helper._Music_name);
  67.       if(Helper._Music != undefined && Helper._Music_playing == false)
  68.       {
  69.          Helper._Music.setVolume(Helper.SoundVolume);
  70.          Helper._Music.start(0,1000);
  71.          Helper._Music_playing = true;
  72.       }
  73.    }
  74.    static function StopMusic()
  75.    {
  76.       Tracer.info("Stop music");
  77.       if(Helper._Music != undefined && Helper._Music_playing == true)
  78.       {
  79.          Helper._Music.stop();
  80.          Helper._Music_playing = false;
  81.       }
  82.    }
  83.    static function LoadMusic(url)
  84.    {
  85.       Tracer.info("Start load music from: " + url);
  86.       Helper._Music_name = url;
  87.       if(Helper._Music == undefined)
  88.       {
  89.          Helper._Music = new Sound();
  90.       }
  91.       Helper._Music.onLoad = function(success)
  92.       {
  93.          if(Helper.OnMusicLoaded != undefined)
  94.          {
  95.             Helper.OnMusicLoaded(success);
  96.          }
  97.       };
  98.       Helper._Music.loadSound(url,false);
  99.    }
  100.    static function AbortMusicLoad()
  101.    {
  102.       if(Helper._Music != undefined)
  103.       {
  104.          delete Helper._Music;
  105.          Helper._Music = undefined;
  106.          if(Helper.OnMusicLoaded != undefined)
  107.          {
  108.             Helper.OnMusicLoaded(false);
  109.          }
  110.       }
  111.    }
  112.    static function ConvertSeconds2TimeString(seconds)
  113.    {
  114.       seconds = Math.floor(seconds);
  115.       var _loc1_ = seconds;
  116.       var _loc2_ = Math.floor(_loc1_ / 60);
  117.       _loc1_ %= 60;
  118.       return (Math.abs(_loc2_) >= 10 ? _loc2_ : "0" + _loc2_) + ":" + (Math.abs(_loc1_) >= 10 ? _loc1_ : "0" + _loc1_);
  119.    }
  120.    static function LoadUrlXML(xml)
  121.    {
  122.       var _loc1_ = xml.firstChild;
  123.       Helper._get_it_url = _loc1_.attributes.url;
  124.       Helper._get_it_target = _loc1_.attributes.window;
  125.       Tracer.info("UrlXML loaded: \"" + Helper._get_it_url + "\", \"" + Helper._get_it_target + "\"");
  126.    }
  127.    static function GetIt()
  128.    {
  129.       if(Helper._get_it_url == undefined)
  130.       {
  131.          Tracer.trace("Get it url not loaded!");
  132.          return undefined;
  133.       }
  134.       getURL(Helper._get_it_url,Helper._get_it_target);
  135.    }
  136.    static function SubtractArray(from, what)
  137.    {
  138.       if(what.length == 0)
  139.       {
  140.          return from;
  141.       }
  142.       var _loc5_ = new Array();
  143.       var _loc2_ = 0;
  144.       while(_loc2_ < from.length)
  145.       {
  146.          var _loc1_ = 0;
  147.          while(_loc1_ < what.length)
  148.          {
  149.             if(from[_loc2_] == what[_loc1_])
  150.             {
  151.                break;
  152.             }
  153.             if(_loc1_ == what.length - 1)
  154.             {
  155.                _loc5_.push(from[_loc2_]);
  156.             }
  157.             _loc1_ = _loc1_ + 1;
  158.          }
  159.          _loc2_ = _loc2_ + 1;
  160.       }
  161.       return _loc5_;
  162.    }
  163.    static function IntersectArray(from, what)
  164.    {
  165.       if(what.length == 0)
  166.       {
  167.          return null;
  168.       }
  169.       if(from.length == 0)
  170.       {
  171.          return null;
  172.       }
  173.       var _loc5_ = new Array();
  174.       var _loc2_ = 0;
  175.       while(_loc2_ < from.length)
  176.       {
  177.          var _loc1_ = 0;
  178.          while(_loc1_ < what.length)
  179.          {
  180.             if(from[_loc2_] == what[_loc1_])
  181.             {
  182.                _loc5_.push(from[_loc2_]);
  183.                break;
  184.             }
  185.             _loc1_ = _loc1_ + 1;
  186.          }
  187.          _loc2_ = _loc2_ + 1;
  188.       }
  189.       return _loc5_;
  190.    }
  191.    static function SearchArray(arr, what)
  192.    {
  193.       var _loc1_ = 0;
  194.       while(_loc1_ < arr.length)
  195.       {
  196.          if(arr[_loc1_] == what)
  197.          {
  198.             return _loc1_;
  199.          }
  200.          _loc1_ = _loc1_ + 1;
  201.       }
  202.       return -1;
  203.    }
  204.    static function GetRandomFromArray(arr)
  205.    {
  206.       if(arr.length == 0)
  207.       {
  208.          return undefined;
  209.       }
  210.       return arr[Math.floor(arr.length * Math.random())];
  211.    }
  212.    static function ClearArray(arr)
  213.    {
  214.       if(arr == undefined)
  215.       {
  216.          return undefined;
  217.       }
  218.       while(arr.length != 0)
  219.       {
  220.          arr.pop();
  221.       }
  222.    }
  223.    static function CreateFPSCounter()
  224.    {
  225.       _root._fps = 0;
  226.       var _loc2_ = _root.createEmptyMovieClip("fps_mc",20000);
  227.       _loc2_.onEnterFrame = function()
  228.       {
  229.          _root._fps = _root._fps + 1;
  230.       };
  231.       _loc2_._x = 200;
  232.       _loc2_.createTextField("tf",10000,0,0,60,20);
  233.       _loc2_.tf.selectable = false;
  234.       _loc2_.tf.backgroundColor = 16777215;
  235.       _loc2_.tf.background = true;
  236.       setInterval(function()
  237.       {
  238.          _root.fps_mc.tf.text = "fps:" + _root._fps;
  239.          _root._fps = 0;
  240.       }
  241.       ,1000);
  242.    }
  243. }
  244.