home *** CD-ROM | disk | FTP | other *** search
/ FCE Gold Plus / GOLD.iso / pc / fscommand / linux / main.swf / scripts / __Packages / com / comp / WordCount.as < prev    next >
Encoding:
Text File  |  2007-09-06  |  7.4 KB  |  223 lines

  1. class com.comp.WordCount extends TextField
  2. {
  3.    var c_txtSource;
  4.    var c_length;
  5.    var c_objRoot;
  6.    var c_txtCount;
  7.    var c_strTmp;
  8.    var c_strTmpLeft;
  9.    var c_iWordLimit;
  10.    function WordCount(_objRoot, _inptxtName, _dynCount, _objTestRef, _iWordLimit)
  11.    {
  12.       var _loc1_ = this;
  13.       super();
  14.       _loc1_.c_objRoot = _objRoot;
  15.       _loc1_.c_txtSource = _loc1_.c_objRoot[_inptxtName];
  16.       _loc1_.c_txtCount = _loc1_.c_objRoot[_dynCount];
  17.       _loc1_.c_objTestRef = _objTestRef;
  18.       _loc1_.c_struserName = com.controller.UICoordinator.getInstance().userName;
  19.       _loc1_.c_strTestMode = _objTestRef.c_strMode;
  20.       _loc1_.c_blnFreezed = false;
  21.       _loc1_.c_iWordLimit = _iWordLimit;
  22.       _loc1_.init();
  23.    }
  24.    function init()
  25.    {
  26.       this.arrange();
  27.    }
  28.    function setQueType(_iPart)
  29.    {
  30.       var _loc1_ = this;
  31.       if(_loc1_.c_objTestRef.c_strSkill.toLowerCase() == "writing")
  32.       {
  33.          var _loc2_ = _loc1_.c_objTestRef.c_hQuestionState["get"]("writing_" + _iPart).attempted;
  34.          _loc1_.c_txtSource.text = _loc2_;
  35.       }
  36.    }
  37.    function arrange()
  38.    {
  39.       var _loc1_ = this;
  40.       _loc1_.c_txtSource.textSize = 10;
  41.       _loc1_.c_txtSource.textColor = 0;
  42.       _loc1_.c_txtSource.border = false;
  43.       _loc1_.c_txtSource.wordWrap = true;
  44.       _loc1_.c_txtSource.multiline = true;
  45.       mcRef = _loc1_.c_objRoot._parent;
  46.       mcRef.wc_ScrollReference._y = mcRef.mc_WordCount._height + mcRef.mc_WordCount._y + 5;
  47.       mcRef.wcScrollPane._y = mcRef.wc_ScrollReference._y;
  48.       if(_loc1_.c_strTestMode != "Review")
  49.       {
  50.          Selection.setFocus(_loc1_.c_txtSource);
  51.       }
  52.       _loc1_.setEvents();
  53.    }
  54.    function countWords()
  55.    {
  56.       var _loc3_ = this.c_txtSource.text.split(String.fromCharCode(13)).join(" ").split(" ");
  57.       var _loc2_ = 0;
  58.       this.c_length = _loc3_.length;
  59.       if(this.c_txtSource.scroll <= 1)
  60.       {
  61.          this.c_objRoot.cmp_ScrollBar._visible = false;
  62.       }
  63.       else
  64.       {
  65.          this.c_objRoot.cmp_ScrollBar._visible = true;
  66.       }
  67.       if(this.c_txtSource.scroll <= 1)
  68.       {
  69.          this.c_objRoot.wcTextScroller._visible = false;
  70.       }
  71.       else
  72.       {
  73.          this.c_objRoot.wcTextScroller._visible = true;
  74.       }
  75.       var _loc1_ = 0;
  76.       while(_loc1_ < _loc3_.length)
  77.       {
  78.          if(_loc3_[_loc1_] != "")
  79.          {
  80.             _loc2_ += 1;
  81.          }
  82.          _loc1_ = _loc1_ + 1;
  83.       }
  84.       this.c_txtCount.text = _loc2_.toString();
  85.    }
  86.    function txt111Changed()
  87.    {
  88.       var _loc1_ = this;
  89.       if(_loc1_.c_txtCount.text > _loc1_.c_iWordLimit)
  90.       {
  91.          _loc1_.c_txtSource.text = _loc1_.c_strTmp;
  92.       }
  93.       else
  94.       {
  95.          _loc1_.c_strTmp = _loc1_.c_txtSource.text;
  96.       }
  97.       _loc1_.c_txtSource.text = _loc1_.c_txtSource.text;
  98.       _loc1_.controlNext(_loc1_);
  99.    }
  100.    function txtChanged()
  101.    {
  102.       this.c_strTmp = this.c_txtSource.text.substr(0,Selection.getBeginIndex());
  103.       this.c_strTmpLeft = this.c_txtSource.text.substr(Selection.getBeginIndex(),this.c_txtSource.text.length);
  104.       if(Number(this.c_txtCount.text) > Number(this.c_iWordLimit))
  105.       {
  106.          var _loc2_ = "";
  107.          var _loc3_ = this.c_strTmp.split(String.fromCharCode(13)).join(" \n").split(" ");
  108.          var arrTmpLeft = this.c_strTmpLeft.split(String.fromCharCode(13)).join(" ").split(" ");
  109.          var ctr = 0;
  110.          var _loc1_ = 0;
  111.          while(_loc1_ < arrTmpLeft.length)
  112.          {
  113.             if(arrTmpLeft[_loc1_] != "")
  114.             {
  115.                ctr += 1;
  116.             }
  117.             _loc1_ = _loc1_ + 1;
  118.          }
  119.          _loc1_ = 0;
  120.          j = 0;
  121.          while(_loc1_ < this.c_iWordLimit - ctr)
  122.          {
  123.             if(_loc3_[j] != "" and _loc3_[j] != undefined and _loc3_[j] != null)
  124.             {
  125.                _loc2_ = _loc2_ + _loc3_[j] + " ";
  126.                _loc1_ = _loc1_ + 1;
  127.             }
  128.             else
  129.             {
  130.                _loc2_ += " ";
  131.             }
  132.             j++;
  133.          }
  134.          if(_loc3_[_loc3_.length - 2] != "")
  135.          {
  136.             if(arrTmpLeft.length > 1)
  137.             {
  138.                _loc2_ += _loc3_[_loc3_.length - 2];
  139.             }
  140.          }
  141.          this.c_txtSource.text = _loc2_.substr(0,_loc2_.length) + this.c_strTmpLeft;
  142.       }
  143.       this.c_txtSource.text = this.c_txtSource.text;
  144.       this.c_txtCount.text = this.c_txtSource.text.split(String.fromCharCode(13)).join(" ").split(" ").length.toString();
  145.       this.controlNext(this);
  146.    }
  147.    function controlNext(_objRef)
  148.    {
  149.       var _loc2_ = this;
  150.       var _loc3_ = _loc2_.c_objRoot.txt_Header.text;
  151.       var len = _loc3_.length;
  152.       var tmp = _loc3_.charAt(len - 1);
  153.       objRef = _loc2_.c_objRoot._parent;
  154.       var _loc1_ = new Object();
  155.       _loc1_.answeroption = tmp;
  156.       if(_objRef.c_txtSource.text == "")
  157.       {
  158.          objRef.btn_next._visible = false;
  159.          _loc1_.attempted = _objRef.c_txtSource.text;
  160.          _loc2_.c_objTestRef.removeQuesObject();
  161.          _loc2_.c_objTestRef.c_objNavigator.markUnAttempted();
  162.       }
  163.       else
  164.       {
  165.          _loc1_.attempted = _objRef.c_txtSource.text;
  166.          _loc2_.c_objTestRef.c_objNavigator.markAttempted();
  167.          objRef.btn_next._visible = true;
  168.          _loc2_.c_objTestRef.appendQuesObject(_loc1_);
  169.       }
  170.    }
  171.    function setEvents()
  172.    {
  173.       var _loc1_ = this;
  174.       Mouse_listener = new Object();
  175.       Mouse_listener.objRef = _loc1_;
  176.       _loc1_.c_txtSource.objRef = _loc1_;
  177.       _loc1_.c_txtSource.onChanged = function()
  178.       {
  179.          var _loc1_ = this;
  180.          _loc1_.objRef.countWords();
  181.          _loc1_.objRef.txtChanged();
  182.          _loc1_.objRef.countWords();
  183.       };
  184.       Mouse_listener.onMouseUp = function()
  185.       {
  186.          var _loc1_ = this;
  187.          if(Selection.getBeginIndex() < _loc1_.objRef.c_txtSource.text.length)
  188.          {
  189.             _loc1_.objRef.c_txtSource.maxChars = 99999;
  190.          }
  191.          else
  192.          {
  193.             _loc1_.objRef.c_txtSource.maxChars = Number(_loc1_.objRef.c_txtSource.text.length);
  194.          }
  195.          _loc1_.objRef.c_txtSource.text = _loc1_.objRef.c_txtSource.text;
  196.       };
  197.       if(_loc1_.c_strTestMode != "Review")
  198.       {
  199.          Key.addListener(Key_listener);
  200.       }
  201.       else if(_loc1_.c_strTestMode == "Review")
  202.       {
  203.          Key.removeListener(Key_listener);
  204.          Mouse.removeListener(Mouse_listener);
  205.       }
  206.       var _btnObjRef = _loc1_;
  207.       _loc1_.c_objRoot._parent.btn_Print.onRelease = function()
  208.       {
  209.          var strQuestionNo = _btnObjRef.c_objRoot._parent.mc_WordCount.txt_QuestionNo.text;
  210.          var stQuestionText = _btnObjRef.c_objRoot._parent.mc_WordCount.txt_Question.htmlText;
  211.          var _loc3_ = _btnObjRef.c_objTestRef.c_objSection;
  212.          var _iTestNum = _loc3_.attributes.test;
  213.          var _loc2_ = _loc3_.attributes.skill;
  214.          _loc2_ = _loc2_.charAt(0).toUpperCase() + _loc2_.substr(1,_loc2_.length);
  215.          var _loc1_ = _loc3_.attributes.type;
  216.          _loc1_ = _loc1_.charAt(0).toUpperCase() + _loc1_.substr(1,_loc1_.length - 1);
  217.          _loc1_ = _loc1_.substr(0,_loc1_.length - 1) + " " + _loc1_.substr(-1);
  218.          var _headerText = com.controller.UICoordinator.getInstance().getTitle() + " - Test: " + _loc2_ + " " + _loc1_;
  219.          com.comp.PrintManager.printIt(_level101.printText_mc,_headerText,_btnObjRef.c_struserName,strQuestionNo,stQuestionText,_btnObjRef.c_txtSource.text);
  220.       };
  221.    }
  222. }
  223.