home *** CD-ROM | disk | FTP | other *** search
/ FCE Gold Plus / GOLD.iso / pc / shell.swf / scripts / __Packages / com / comp / WordCount.as < prev    next >
Text File  |  2007-10-16  |  7KB  |  216 lines

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