home *** CD-ROM | disk | FTP | other *** search
/ Practice Anatomy Lab / PAL.ISO / pc / PAL.swf / scripts / __Packages / com / argosy / ui / SummaryViewer.as < prev    next >
Encoding:
Text File  |  2007-03-19  |  11.8 KB  |  284 lines

  1. class com.argosy.ui.SummaryViewer extends com.argosy.ui.baseUI
  2. {
  3.    var activity_mode;
  4.    var correct_count;
  5.    var content_mc;
  6.    var mask;
  7.    var question_items;
  8.    var scroll_bar;
  9.    var summary_style;
  10.    var reset_button;
  11.    var top_feedback;
  12.    var bg;
  13.    var dispatchEvent;
  14.    function SummaryViewer()
  15.    {
  16.       super();
  17.    }
  18.    function clearContent()
  19.    {
  20.       this._visible = false;
  21.    }
  22.    function setContent(act_mode, question_array)
  23.    {
  24.       trace("Summary: setContent");
  25.       this._visible = true;
  26.       this.activity_mode = act_mode;
  27.       this.correct_count = 0;
  28.       this.content_mc = this.createEmptyMovieClip("content_mc",3);
  29.       this.content_mc.setMask(this.mask);
  30.       this.content_mc._y = this.mask._y;
  31.       this.question_items = [];
  32.       var _loc3_ = 0;
  33.       while(_loc3_ < question_array.length)
  34.       {
  35.          var _loc2_ = this.content_mc.createEmptyMovieClip("item_" + _loc3_,1 + _loc3_);
  36.          _loc2_.question_object = question_array[_loc3_];
  37.          _loc2_.isOpen = false;
  38.          _loc2_.bg = _loc2_.createEmptyMovieClip("bg",1);
  39.          _loc2_.image_button = _loc2_.attachMovie("folder_arrow","image_button",300);
  40.          _loc2_.image_button._x = 10 + _loc2_.image_button._width / 2;
  41.          _loc2_.image_button._y = 10 + _loc2_.image_button._height / 2;
  42.          _loc2_.image_button.onPress = ascb.util.Proxy.create(this,this.toggle_image,_loc2_);
  43.          _loc2_.label_tf = this._createTextField(_loc2_,"label_tf",100,30,10,this.width - this.scroll_bar._width - 50,20,this.summary_style,"");
  44.          _loc2_.label_tf.multiline = true;
  45.          _loc2_.label_tf.wordWrap = true;
  46.          _loc2_.label_tf.autoSize = true;
  47.          if(question_array[_loc3_].isCorrect)
  48.          {
  49.             this.correct_count = this.correct_count + 1;
  50.             _loc2_.label_tf.htmlText = "<p><title>Problem " + (_loc3_ + 1) + ": </title> <summary_right>Correct</summary_right></p>";
  51.          }
  52.          else
  53.          {
  54.             _loc2_.label_tf.htmlText = "<p><title>Problem " + (_loc3_ + 1) + ": </title> <summary_wrong>Incorrect</summary_wrong></p>" + this.buildSummaryText(question_array[_loc3_]);
  55.          }
  56.          _loc2_.label_tf.htmlText += "<p align =\'right\'>" + (_loc3_ + 1) + " out of " + question_array.length + "</p>";
  57.          _loc2_.image_button._visible = question_array[_loc3_].image != undefined;
  58.          this.draw_item(_loc2_);
  59.          _loc2_.image_bitmap = question_array[_loc3_].image;
  60.          this.question_items.push(_loc2_);
  61.          _loc3_ = _loc3_ + 1;
  62.       }
  63.       this.layout_items();
  64.       if(this.activity_mode == "Lab Practical")
  65.       {
  66.          this.reset_button = this.attachMovie("take_exam_again_button","reset_button",10);
  67.       }
  68.       else
  69.       {
  70.          this.reset_button = this.attachMovie("take_quiz_again_button","reset_button",10);
  71.       }
  72.       this.reset_button.onRelease = ascb.util.Proxy.create(this,this.reset_button_press);
  73.       this.reset_button._x = 10 + this.reset_button._width / 2;
  74.       this.reset_button._y = this.mask._y + this.mask._height + this.reset_button._height / 2 + 10;
  75.       if(this.correct_count == question_array.length)
  76.       {
  77.          this.top_feedback.htmlText = "<p><topfeedback>You answered all <summary_right>" + question_array.length + "</summary_right> questions correctly.</topfeedback></p>";
  78.       }
  79.       else
  80.       {
  81.          this.top_feedback.htmlText = "<p><topfeedback>You answered <summary_wrong>" + this.correct_count + "</summary_wrong> out of <summary_right>" + question_array.length + "</summary_right> questions correctly.</topfeedback></p>";
  82.       }
  83.       this.scroll_bar.position = 0;
  84.    }
  85.    function buildSummaryText(current_question)
  86.    {
  87.       var _loc3_ = current_question.isCorrect;
  88.       var _loc4_ = "";
  89.       switch(current_question.type)
  90.       {
  91.          case "fill_in":
  92.             if(_loc3_ == false || _loc3_ == null)
  93.             {
  94.                if(current_question.user_input == undefined || current_question.user_input == "")
  95.                {
  96.                   _loc4_ = "<p>The correct answer was: <summary_right>" + current_question.answers[0] + "</summary_right></p>";
  97.                }
  98.                else
  99.                {
  100.                   _loc4_ = "<p>You said: <summary_wrong>" + current_question.user_input + "</summary_wrong> but the correct answer was: <summary_right>" + current_question.answers[0] + "</summary_right></p>";
  101.                }
  102.             }
  103.             break;
  104.          case "multi_choice":
  105.             if(_loc3_ == false || _loc3_ == null)
  106.             {
  107.                if(current_question.answer_text == undefined)
  108.                {
  109.                   var _loc2_ = 0;
  110.                   while(_loc2_ < current_question.options.length)
  111.                   {
  112.                      if(current_question.options[_loc2_].correct)
  113.                      {
  114.                         current_question.answer_text = current_question.options[_loc2_].label;
  115.                         break;
  116.                      }
  117.                      _loc2_ = _loc2_ + 1;
  118.                   }
  119.                }
  120.                if(_loc3_ == false || _loc3_ == null)
  121.                {
  122.                   if(current_question.user_input == undefined)
  123.                   {
  124.                      _loc4_ = "<p>The correct answer was: <summary_right>" + current_question.answer_text + "</summary_right></p>";
  125.                   }
  126.                   else
  127.                   {
  128.                      _loc4_ = "<p>You said: <summary_wrong>" + current_question.user_input + "</summary_wrong> but the correct answer was: <summary_right>" + current_question.answer_text + "</summary_right></p>";
  129.                   }
  130.                }
  131.             }
  132.             break;
  133.          case "true_false":
  134.             var _loc5_ = current_question.answer.split("");
  135.             _loc5_[0] = _loc5_[0].toUpperCase();
  136.             var _loc6_ = _loc5_.join("");
  137.             if(_loc3_ == false || _loc3_ == null)
  138.             {
  139.                _loc4_ = "<p>The correct answer was: <summary_right>" + _loc6_ + "</summary_right></p>";
  140.             }
  141.             break;
  142.          case "matching":
  143.             if(_loc3_ == false)
  144.             {
  145.                _loc4_ = "<p>You matched <summary_wrong>" + current_question.correct_count + "</summary_wrong> out of <summary_right>" + current_question.question_count + "</summary_right> correctly.</p>";
  146.             }
  147.             else if(_loc3_ == undefined || _loc3_ == null)
  148.             {
  149.                _loc4_ = "<p>You matched <summary_wrong>0</summary_wrong> out of <summary_right>" + current_question.questions.length + "</summary_right> correctly.</p>";
  150.             }
  151.             break;
  152.          case "flag":
  153.          case "pin":
  154.             if(_loc3_ == false)
  155.             {
  156.                _loc4_ = "<p>You labeled <summary_wrong>" + current_question.correct_count + "</summary_wrong> out of <summary_right>" + current_question.question_count + "</summary_right> correctly.</p>";
  157.             }
  158.             else if(_loc3_ == undefined || _loc3_ == null)
  159.             {
  160.                _loc4_ = "<p>You labeled <summary_wrong>0</summary_wrong> out of <summary_right>" + current_question.hotspot_array.length + "</summary_right> correctly.</p>";
  161.             }
  162.       }
  163.       return _loc4_;
  164.    }
  165.    function draw_item(mc)
  166.    {
  167.       if(mc.isOpen)
  168.       {
  169.          mc.image = mc.createEmptyMovieClip("image",200);
  170.          mc.image.attachBitmap(mc.image_bitmap,1,true,true);
  171.          mc.image._xscale = mc.image._yscale = 90;
  172.          mc.image._y = mc.label_tf._y + mc.label_tf._height + 10;
  173.          mc.image._x = (this.width - this.scroll_bar._width - 20) / 2 - mc.image._width / 2;
  174.          var _loc4_ = mc.image._y + mc.image._height + 20;
  175.       }
  176.       else
  177.       {
  178.          mc.image.removeMovieClip();
  179.          _loc4_ = mc.label_tf._y + mc.label_tf._height;
  180.       }
  181.       var _loc3_ = 2;
  182.       mc.bg.clear();
  183.       mc.bg.lineStyle(0,0,0);
  184.       mc.bg.beginFill(9543123,20);
  185.       com.drawing.drawUtil.drawRect(mc.bg,_loc3_,_loc3_,this.width - this.scroll_bar._width - _loc3_ - 10,_loc4_ - _loc3_,10);
  186.       mc.bg.endFill();
  187.    }
  188.    function toggle_image(image_mc)
  189.    {
  190.       image_mc.isOpen = !image_mc.isOpen;
  191.       image_mc.image_button._rotation = !image_mc.isOpen ? 0 : 90;
  192.       image_mc.image._visible = image_mc.isOpen;
  193.       this.draw_item(image_mc);
  194.       this.layout_items();
  195.    }
  196.    function layout_items()
  197.    {
  198.       trace("layout_items");
  199.       var _loc2_ = 0;
  200.       while(_loc2_ < this.question_items.length)
  201.       {
  202.          if(_loc2_ == 0)
  203.          {
  204.             this.question_items[_loc2_]._y = 0;
  205.          }
  206.          else
  207.          {
  208.             this.question_items[_loc2_]._y = this.question_items[_loc2_ - 1]._y + this.question_items[_loc2_ - 1].bg._height + 2;
  209.          }
  210.          _loc2_ = _loc2_ + 1;
  211.       }
  212.       this.set_scroll(this.question_items[this.question_items.length - 1]._y + this.question_items[this.question_items.length - 1].bg._height + 10);
  213.    }
  214.    function init()
  215.    {
  216.       trace("INIT::SummaryViewer");
  217.       this.summary_style = new TextField.StyleSheet();
  218.       this.summary_style.setStyle("p",{fontFamily:"Frutiger Bold",fontSize:"12",color:"#000000",textAlign:"left",textDecoration:"none",kerning:"true",letterSpacing:"0"});
  219.       this.summary_style.setStyle("topfeedback",{display:"inline",fontFamily:"Frutiger Bold",fontSize:"18",color:"#000000"});
  220.       this.summary_style.setStyle("title",{display:"inline",fontFamily:"Frutiger Bold",fontSize:"14",color:"#000000"});
  221.       this.summary_style.setStyle("summary_right",{display:"inline",fontFamily:"Frutiger Bold",color:"#009900"});
  222.       this.summary_style.setStyle("summary_wrong",{display:"inline",fontFamily:"Frutiger Bold",color:"#990000"});
  223.       super.init();
  224.       this.clearContent();
  225.    }
  226.    function set_scroll(h)
  227.    {
  228.       var _loc2_ = this.content_mc._height;
  229.       if(_loc2_ > this.mask._height)
  230.       {
  231.          this.scroll_bar.setReferenceSize(_loc2_,this.mask._height);
  232.          this.scroll_bar._visible = true;
  233.          this.scroll_bar.position = (this.mask._y - this.content_mc._y) / (this.content_mc._height - this.mask._height);
  234.       }
  235.       else
  236.       {
  237.          this.scroll_bar.setReferenceSize(this.mask._height,this.mask._height);
  238.          this.scroll_bar._visible = false;
  239.       }
  240.    }
  241.    function scroll_event(evt)
  242.    {
  243.       this.content_mc._y = this.mask._y - (this.content_mc._height - this.mask._height) * evt.value;
  244.    }
  245.    function createChildren()
  246.    {
  247.       this.top_feedback = this._createTextField(this,"top_feedback",100,0,0,10,20,this.summary_style,"");
  248.       this.top_feedback.autoSize = true;
  249.       this.bg = this.createEmptyMovieClip("bg",1);
  250.       this.mask = this.createEmptyMovieClip("mask",2);
  251.       this.scroll_bar = this.attachMovie("ScrollBar","scroll_bar",4);
  252.       this.scroll_bar.addEventListener("onScroll",this,"scroll_event");
  253.    }
  254.    function reset_button_press()
  255.    {
  256.       trace("reset");
  257.       this.dispatchEvent({type:"reset_activity",target:this});
  258.    }
  259.    function layout()
  260.    {
  261.       this.bg.clear();
  262.       this.bg.lineStyle(0,16777215,100);
  263.       this.bg.beginFill(16777215,0);
  264.       this.bg.lineTo(this.width,0);
  265.       this.bg.lineTo(this.width,this.height);
  266.       this.bg.lineTo(0,this.height);
  267.       this.bg.lineTo(0,0);
  268.       this.bg.endFill();
  269.       this.mask._y = 30;
  270.       this.mask.clear();
  271.       this.mask.lineStyle(0,16711680,0);
  272.       this.mask.beginFill(16711680,0);
  273.       this.mask.moveTo(0,0);
  274.       this.mask.lineTo(this.width - this.scroll_bar._width,0);
  275.       this.mask.lineTo(this.width - this.scroll_bar._width,this.height - 60);
  276.       this.mask.lineTo(0,this.height - 60);
  277.       this.mask.lineTo(0,0);
  278.       this.mask.endFill();
  279.       this.scroll_bar._y = this.mask._y;
  280.       this.scroll_bar._x = this.mask._width;
  281.       this.scroll_bar.height = this.mask._height;
  282.    }
  283. }
  284.