home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Swf / Completos.swf / scripts / FTicker.as < prev    next >
Text File  |  2010-02-24  |  7KB  |  297 lines

  1. function FTickerClass()
  2. {
  3.    ASBroadcaster.initialize(this);
  4.    this.originalWidth = 180;
  5.    this.originalHeight = 20;
  6.    this.currentMessage = 0;
  7.    if(!this.tickerMessages)
  8.    {
  9.       this.tickerMessages = new Array();
  10.    }
  11.    this.init();
  12. }
  13. FTickerClass.prototype = new MovieClip();
  14. FTickerClass.prototype.init = function()
  15. {
  16.    this.makeText();
  17.    this.preventScale();
  18.    if(this.tickerMessages[this.currentMessage] != undefined)
  19.    {
  20.       this.setText(this.currentMessage);
  21.    }
  22.    this.formatText();
  23.    this.scrollText();
  24. };
  25. FTickerClass.prototype.makeText = function()
  26. {
  27.    this.attachMovie("tickertxt_mc","tickertxt_mc",1);
  28.    tickertxt_mc._width = this.originalWidth;
  29.    tickertxt_mc._height = this.originalHeight;
  30. };
  31. FTickerClass.prototype.formatText = function()
  32. {
  33.    this.tickertxt_mc.ticker.autosize = true;
  34.    this.tickerFormat = new TextFormat();
  35.    with(this.tickerFormat)
  36.    {
  37.       selectable = false;
  38.       size = this.tickerSize;
  39.       color = this.tickerColor;
  40.    }
  41.    this.tickertxt_mc.ticker.setTextFormat(this.tickerFormat);
  42. };
  43. FTickerClass.prototype.positionText = function()
  44. {
  45.    if(this.scrollDirection == "left")
  46.    {
  47.       this.tickertxt_mc._x = this.tickermask_mc._width;
  48.    }
  49.    else
  50.    {
  51.       this.tickertxt_mc._x = this.tickertxt_mc._width * -1;
  52.    }
  53.    this.broadcast();
  54.    switch(this.textAlign)
  55.    {
  56.       case "top":
  57.          this.tickertxt_mc._y = 0;
  58.          break;
  59.       case "middle":
  60.          this.tickertxt_mc._y = (this.tickermask_mc._height - this.tickertxt_mc._height) / 2;
  61.          break;
  62.       case "bottom":
  63.          this.tickertxt_mc._y = this.tickermask_mc._height - this.tickertxt_mc._height;
  64.    }
  65.    this.tickertxt_mc.setMask(this.tickermask_mc);
  66. };
  67. FTickerClass.prototype.scrollText = function()
  68. {
  69.    this.positionText();
  70.    this.onEnterFrame = function()
  71.    {
  72.       if(this.scrollDirection == "left")
  73.       {
  74.          if(this.tickertxt_mc._x > this.tickertxt_mc._width * -1)
  75.          {
  76.             if(!this.pause)
  77.             {
  78.                this.tickertxt_mc._x -= this.scrollSpeed;
  79.             }
  80.          }
  81.          else
  82.          {
  83.             this.nextMessage();
  84.          }
  85.       }
  86.       else if(this.tickertxt_mc._x < this.tickermask_mc._width)
  87.       {
  88.          if(!this.pause)
  89.          {
  90.             this.tickertxt_mc._x += this.scrollSpeed;
  91.          }
  92.       }
  93.       else
  94.       {
  95.          this.nextMessage();
  96.       }
  97.       if(this.pauseScroll)
  98.       {
  99.          this.checkPause();
  100.       }
  101.    };
  102. };
  103. FTickerClass.prototype.checkPause = function()
  104. {
  105.    if(this.tickertxt_mc.hitTest(_root._xmouse,_root._ymouse,false))
  106.    {
  107.       this.pause = true;
  108.    }
  109.    else
  110.    {
  111.       this.pause = false;
  112.    }
  113. };
  114. FTickerClass.prototype.nextMessage = function()
  115. {
  116.    if(this.currentMessage < this.tickerMessages.length - 1)
  117.    {
  118.       this.currentMessage = this.currentMessage + 1;
  119.    }
  120.    else
  121.    {
  122.       this.currentMessage = 0;
  123.    }
  124.    this.setText(this.currentMessage);
  125.    this.formatText();
  126.    this.positionText();
  127. };
  128. FTickerClass.prototype.broadcast = function()
  129. {
  130.    this.currentMessage;
  131.    this.broadcastMessage("onScroll",this.currentMessage);
  132. };
  133. FTickerClass.prototype.preventScale = function()
  134. {
  135.    var _loc3_ = this._width / (this.originalWidth / 2);
  136.    var _loc2_ = this._height / this.originalHeight;
  137.    this.tickertxt_mc._width /= _loc3_;
  138.    this.tickertxt_mc._height /= _loc2_;
  139. };
  140. FTickerClass.prototype.setText = function(message)
  141. {
  142.    this.tickertxt_mc.ticker.htmlText = this.tickerMessages[message];
  143. };
  144. FTickerClass.prototype.getText = function()
  145. {
  146.    return this.tickerMessages[this.currentMessage];
  147. };
  148. FTickerClass.prototype.setSpeed = function(speed)
  149. {
  150.    this.scrollSpeed = speed;
  151. };
  152. FTickerClass.prototype.getSpeed = function()
  153. {
  154.    return this.scrollSpeed;
  155. };
  156. FTickerClass.prototype.setDirection = function(direction)
  157. {
  158.    this.scrollDirection = direction;
  159. };
  160. FTickerClass.prototype.getDirection = function()
  161. {
  162.    return this.scrollDirection;
  163. };
  164. FTickerClass.prototype.getQueue = function()
  165. {
  166.    var _loc2_ = this.currentMessage;
  167.    var _loc4_ = new Array();
  168.    var _loc3_ = 0;
  169.    while(_loc3_ < this.tickerMessages.length)
  170.    {
  171.       _loc4_.push(this.tickerMessages[_loc2_]);
  172.       if(_loc2_ < this.tickerMessages.length - 1)
  173.       {
  174.          _loc2_ = _loc2_ + 1;
  175.       }
  176.       else
  177.       {
  178.          _loc2_ = 0;
  179.       }
  180.       _loc3_ = _loc3_ + 1;
  181.    }
  182.    return _loc4_;
  183. };
  184. FTickerClass.prototype.getMessageID = function()
  185. {
  186.    return this.currentMessage;
  187. };
  188. FTickerClass.prototype.setPause = function(bool)
  189. {
  190.    if(bool)
  191.    {
  192.       this.pauseScroll = true;
  193.    }
  194.    else
  195.    {
  196.       this.pauseScroll = false;
  197.    }
  198. };
  199. FTickerClass.prototype.getPause = function()
  200. {
  201.    return this.pauseScroll;
  202. };
  203. FTickerClass.prototype.setAlign = function(alignment)
  204. {
  205.    this.textAlign = alignment;
  206.    switch(this.textAlign)
  207.    {
  208.       case "top":
  209.          this.tickertxt_mc._y = 0;
  210.          break;
  211.       case "middle":
  212.          this.tickertxt_mc._y = (this.tickermask_mc._height - this.tickertxt_mc._height) / 2;
  213.          break;
  214.       case "bottom":
  215.          this.tickertxt_mc._y = this.tickermask_mc._height - this.tickertxt_mc._height;
  216.    }
  217. };
  218. FTickerClass.prototype.getAlign = function()
  219. {
  220.    return this.textAlign;
  221. };
  222. FTickerClass.prototype.setColor = function(textcolor)
  223. {
  224.    this.tickerColor = textcolor;
  225.    this.formatText();
  226. };
  227. FTickerClass.prototype.getColor = function()
  228. {
  229.    return this.tickerColor;
  230. };
  231. FTickerClass.prototype.setSize = function(size)
  232. {
  233.    this.tickerSize = size;
  234.    this.formatText();
  235.    this.setAlign(this.textAlign);
  236. };
  237. FTickerClass.prototype.getSize = function()
  238. {
  239.    return this.tickerSize;
  240. };
  241. FTickerClass.prototype.addMessage = function(newtext)
  242. {
  243.    this.tickerMessages.push(newtext);
  244.    this.setText(this.currentMessage);
  245.    this.formatText();
  246. };
  247. FTickerClass.prototype.removeMessage = function(textid)
  248. {
  249.    if(typeof textid == "number")
  250.    {
  251.       this.tickerMessages.splice(textid,1);
  252.    }
  253.    else
  254.    {
  255.       var _loc2_ = 0;
  256.       while(_loc2_ < this.tickerMessages.length)
  257.       {
  258.          if(this.tickerMessages[_loc2_] == textid)
  259.          {
  260.             this.tickerMessages.splice(_loc2_,1);
  261.          }
  262.          _loc2_ = _loc2_ + 1;
  263.       }
  264.    }
  265. };
  266. FTickerClass.prototype.switchMessage = function(from, to)
  267. {
  268.    if(typeof from == "number")
  269.    {
  270.       var _loc4_ = this.tickerMessages[from];
  271.       var _loc3_ = this.tickerMessages[to];
  272.    }
  273.    else
  274.    {
  275.       var _loc2_ = 0;
  276.       while(_loc2_ < this.tickerMessages.length)
  277.       {
  278.          if(this.tickerMessages[_loc2_] == from)
  279.          {
  280.             _loc4_ = _loc2_;
  281.          }
  282.          if(this.tickerMessages[_loc2_] == to)
  283.          {
  284.             _loc3_ = _loc2_;
  285.          }
  286.          _loc2_ = _loc2_ + 1;
  287.       }
  288.       this.tickerMessages[_loc4_] = to;
  289.       this.tickerMessages[_loc3_] = from;
  290.    }
  291.    this.tickerMessages[from] = _loc3_;
  292.    this.tickerMessages[to] = _loc4_;
  293.    this.setText(this.currentMessage);
  294.    this.formatText();
  295. };
  296. Object.registerClass("FTicker",FTickerClass);
  297.