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

  1. class com.argosy.ui.LabelViewer extends com.argosy.ui.baseUI
  2. {
  3.    var xml_loader;
  4.    var base_url;
  5.    var soundPlayer;
  6.    var image_array;
  7.    var current_image;
  8.    var image_holder;
  9.    var image_loader;
  10.    var mask;
  11.    var caption_tf;
  12.    var instructions_tf;
  13.    var location_tf;
  14.    var view_labels_button;
  15.    var hide_labels_button;
  16.    var bg;
  17.    var uiPanel;
  18.    var button_holder;
  19.    var back_button;
  20.    var next_button;
  21.    var load_bar;
  22.    static var label_style;
  23.    var isComplete = true;
  24.    var uiPanelWidth = 220;
  25.    var showAllOutlines = false;
  26.    var showAllLabels = false;
  27.    var showRollOvers = true;
  28.    function LabelViewer()
  29.    {
  30.       super();
  31.    }
  32.    function loadContent(url)
  33.    {
  34.       trace("loadContent:" + url);
  35.       this.xml_loader.load(url);
  36.    }
  37.    function sound_press(evt)
  38.    {
  39.       trace("sound_press");
  40.       this.soundPlayer.loadSound(this.base_url + evt.target.audio,true);
  41.       this.soundPlayer.setVolume(_global.user_volume * 2);
  42.    }
  43.    function sound_load(success)
  44.    {
  45.       trace("sound_loaded: " + success);
  46.    }
  47.    function xml_loaded(success)
  48.    {
  49.       if(success)
  50.       {
  51.          trace("success");
  52.          if(this.xml_loader.status == 0)
  53.          {
  54.             this.base_url = this.xml_loader.firstChild.attributes.base_url != undefined ? this.xml_loader.firstChild.attributes.base_url : "";
  55.             trace("XML Loaded");
  56.             this.image_array = [];
  57.             var _loc5_ = 0;
  58.             while(_loc5_ < this.xml_loader.firstChild.childNodes.length)
  59.             {
  60.                if(this.xml_loader.firstChild.childNodes[_loc5_].nodeName == "image")
  61.                {
  62.                   var _loc4_ = {};
  63.                   _loc4_.index = this.image_array.length;
  64.                   _loc4_.image_url = this.xml_loader.firstChild.childNodes[_loc5_].attributes.image_url;
  65.                   _loc4_.image_id = this.xml_loader.firstChild.childNodes[_loc5_].attributes.image_id;
  66.                   _loc4_.hotspot_array = [];
  67.                   var _loc6_ = 0;
  68.                   while(_loc6_ < this.xml_loader.firstChild.childNodes[_loc5_].childNodes.length)
  69.                   {
  70.                      var _loc2_ = this.xml_loader.firstChild.childNodes[_loc5_].childNodes[_loc6_];
  71.                      switch(_loc2_.nodeName)
  72.                      {
  73.                         case "instructions":
  74.                            _loc4_.instructions = _loc2_.firstChild.nodeValue;
  75.                            break;
  76.                         case "caption":
  77.                            _loc4_.caption = _loc2_.firstChild.nodeValue;
  78.                            break;
  79.                         case "hotspot":
  80.                            var _loc3_ = new com.argosy.ui.LabelHotSpot();
  81.                            _loc3_.id = _loc2_.attributes.id;
  82.                            _loc3_.color = _loc2_.attributes.color;
  83.                            _loc3_.audio = _loc2_.attributes.audio;
  84.                            _loc3_.type = _loc2_.attributes.type;
  85.                            _loc3_.label = _loc2_.firstChild.nodeValue;
  86.                            _loc3_.addEventListener("press",this,"sound_press");
  87.                            _loc4_.hotspot_array.push(_loc3_);
  88.                      }
  89.                      _loc6_ = _loc6_ + 1;
  90.                   }
  91.                   this.image_array.push(_loc4_);
  92.                }
  93.                _loc5_ = _loc5_ + 1;
  94.             }
  95.          }
  96.          else
  97.          {
  98.             trace("XML Parse Error: " + this.xml_loader.status);
  99.          }
  100.       }
  101.       else
  102.       {
  103.          trace("XML Can\'t Load");
  104.       }
  105.       this.loadImage(this.image_array[0]);
  106.    }
  107.    function loadNextNumber()
  108.    {
  109.       this.loadImageNumber(this.current_image.index + 1);
  110.    }
  111.    function loadLastNumber()
  112.    {
  113.       this.loadImageNumber(this.current_image.index - 1);
  114.    }
  115.    function loadImageNumber(image_num)
  116.    {
  117.       trace("loadImageNumber: " + image_num);
  118.       if(image_num < 0)
  119.       {
  120.          image_num = this.image_array.length - 1;
  121.       }
  122.       else if(image_num >= this.image_array.length)
  123.       {
  124.          image_num = 0;
  125.       }
  126.       trace("loadImageNumber_2: " + image_num);
  127.       this.loadImage(this.image_array[image_num]);
  128.    }
  129.    function loadImage(image_obj)
  130.    {
  131.       trace("labelViewer: loadImage - " + image_obj.index);
  132.       this.current_image = image_obj;
  133.       this.image_holder = this.createEmptyMovieClip("image_holder",100);
  134.       this.image_holder._x = 225;
  135.       this.image_holder._y = 5;
  136.       this.image_loader.loadClip(this.base_url + this.current_image.image_url,this.image_holder);
  137.       this.image_holder.setMask(this.mask);
  138.       this.image_holder._visible = false;
  139.       this.caption_tf.htmlText = "<p><caption>" + this.current_image.caption + "</caption></p>";
  140.       this.instructions_tf.htmlText = "<p><instruction>" + this.current_image.instructions + "</instruction></p>";
  141.       this.location_tf.htmlText = "<p><location>Image " + (image_obj.index + 1) + " out of " + this.image_array.length + "</location></p>";
  142.       this.layout();
  143.       this.setLabelButton(false);
  144.    }
  145.    function setLabelButton(b)
  146.    {
  147.       this.showAllLabels = b;
  148.       if(this.showAllLabels)
  149.       {
  150.          this.view_labels_button._visible = false;
  151.          this.hide_labels_button._visible = true;
  152.       }
  153.       else
  154.       {
  155.          this.view_labels_button._visible = true;
  156.          this.hide_labels_button._visible = false;
  157.       }
  158.       for(var _loc2_ in this.current_image.hotspot_array)
  159.       {
  160.          this.current_image.hotspot_array[_loc2_].showLabels = this.showAllLabels;
  161.       }
  162.    }
  163.    function findHotSpots(mc)
  164.    {
  165.       trace("findHotSpots");
  166.       for(var _loc3_ in mc)
  167.       {
  168.          mc[_loc3_]._visible = false;
  169.       }
  170.       for(_loc3_ in this.current_image.hotspot_array)
  171.       {
  172.          this.current_image.hotspot_array[_loc3_].graphic = this.image_holder["hs_" + this.current_image.hotspot_array[_loc3_].id];
  173.          this.current_image.hotspot_array[_loc3_].graphic._visible = true;
  174.       }
  175.       this.image_holder._visible = true;
  176.    }
  177.    function init()
  178.    {
  179.       trace("Label Viewer");
  180.       this.image_loader = new MovieClipLoader();
  181.       this.image_loader.addListener(this);
  182.       this.xml_loader = new XML();
  183.       this.xml_loader.ignoreWhite = true;
  184.       this.xml_loader.onLoad = ascb.util.Proxy.create(this,this.xml_loaded);
  185.       this.soundPlayer = new Sound();
  186.       this.soundPlayer.onLoad = ascb.util.Proxy.create(this,this.sound_load);
  187.       if(com.argosy.ui.LabelViewer.label_style == undefined)
  188.       {
  189.          com.argosy.ui.LabelViewer.label_style = new TextField.StyleSheet();
  190.          com.argosy.ui.LabelViewer.label_style.setStyle("p",{fontFamily:"Frutiger Bold",fontSize:"12",color:"#999999",textAlign:"left",textDecoration:"none",kerning:"true",letterSpacing:"0"});
  191.          com.argosy.ui.LabelViewer.label_style.setStyle("caption",{fontSize:"14",color:"#999999",textAlign:"right"});
  192.          com.argosy.ui.LabelViewer.label_style.setStyle("instruction",{fontFamily:"Frutiger",fontSize:"12",color:"#000000",textAlign:"left",marginLeft:"10",marginRight:"10"});
  193.          com.argosy.ui.LabelViewer.label_style.setStyle("location",{fontSize:"9",color:"#000000",textAlign:"center"});
  194.       }
  195.       super.init();
  196.    }
  197.    function createChildren()
  198.    {
  199.       this.bg = this.createEmptyMovieClip("bg",1);
  200.       this.mask = this.createEmptyMovieClip("mask",2000);
  201.       this.caption_tf = this._createTextField(this,"caption_tf",300,this.uiPanelWidth,0,this.width - this.uiPanelWidth - 10,20,com.argosy.ui.LabelViewer.label_style,"");
  202.       this.uiPanel = this.createEmptyMovieClip("uiPanel",2);
  203.       this.button_holder = this.uiPanel.createEmptyMovieClip("button_holder",1);
  204.       this.back_button = this.button_holder.attachMovie("back_button","back_button",1);
  205.       this.next_button = this.button_holder.attachMovie("next_button","next_button",2);
  206.       this.next_button.onRelease = ascb.util.Proxy.create(this,this.loadNextNumber);
  207.       this.back_button.onRelease = ascb.util.Proxy.create(this,this.loadLastNumber);
  208.       this.location_tf = this._createTextField(this.button_holder,"location_tf",3,0,10,this.uiPanelWidth,20,com.argosy.ui.LabelViewer.label_style,"");
  209.       this.instructions_tf = this._createTextField(this.uiPanel,"instructions_tf",3,0,10,this.uiPanelWidth,10,com.argosy.ui.LabelViewer.label_style,"");
  210.       this.instructions_tf.multiline = true;
  211.       this.instructions_tf.wordWrap = true;
  212.       this.instructions_tf.autoSize = true;
  213.       this.view_labels_button = this.uiPanel.attachMovie("view_labels","view_labels_button",4);
  214.       this.hide_labels_button = this.uiPanel.attachMovie("hide_labels","hide_labels_button",5);
  215.       this.view_labels_button.onRelease = ascb.util.Proxy.create(this,this.setLabelButton,true);
  216.       this.hide_labels_button.onRelease = ascb.util.Proxy.create(this,this.setLabelButton,false);
  217.       this.load_bar = this.attachMovie("LoadBar","load_bar",200);
  218.       this.layout();
  219.       this.setLabelButton(false);
  220.    }
  221.    function layout()
  222.    {
  223.       this.bg.clear();
  224.       this.bg.beginFill(16777215,100);
  225.       this.bg.lineTo(this.width,0);
  226.       this.bg.lineTo(this.width,this.height);
  227.       this.bg.lineTo(0,this.height);
  228.       this.bg.lineTo(0,0);
  229.       this.bg.endFill();
  230.       this.mask.clear();
  231.       this.mask.lineStyle(0,16711680,0);
  232.       this.mask.beginFill(16711680,0);
  233.       this.mask.moveTo(this.uiPanelWidth,0);
  234.       this.mask.lineTo(this.width - 1,0);
  235.       this.mask.lineTo(this.width - 1,this.height - 1);
  236.       this.mask.lineTo(this.uiPanelWidth,this.height - 1);
  237.       this.mask.lineTo(this.uiPanelWidth,0);
  238.       this.mask.endFill();
  239.       this.uiPanel.clear();
  240.       var _loc2_ = new flash.geom.Matrix();
  241.       _loc2_.createGradientBox(this.uiPanelWidth,this.height,1.5707963267948966,0,0);
  242.       this.uiPanel.beginGradientFill("linear",[14409183,10856103],[100,100],[0,255],_loc2_,"pad");
  243.       this.uiPanel.lineTo(this.uiPanelWidth,0);
  244.       this.uiPanel.lineTo(this.uiPanelWidth,this.height);
  245.       this.uiPanel.lineTo(0,this.height);
  246.       this.uiPanel.lineTo(0,0);
  247.       this.uiPanel.endFill();
  248.       this.uiPanel.lineStyle(0,6710886,100);
  249.       this.uiPanel.moveTo(0,0);
  250.       this.uiPanel.lineTo(this.uiPanelWidth,0);
  251.       this.uiPanel.lineTo(this.uiPanelWidth,this.height);
  252.       this.uiPanel.lineTo(0,this.height);
  253.       this.uiPanel.lineTo(0,0);
  254.       this.view_labels_button._x = this.uiPanelWidth / 2;
  255.       this.view_labels_button._y = this.instructions_tf._y + this.instructions_tf._height + this.view_labels_button._height / 2 + 20;
  256.       this.hide_labels_button._x = this.uiPanelWidth / 2;
  257.       this.hide_labels_button._y = this.instructions_tf._y + this.instructions_tf._height + this.hide_labels_button._height / 2 + 20;
  258.       this.back_button._x = this.back_button._width;
  259.       this.next_button._x = this.back_button._x + this.back_button._width + 20;
  260.       this.location_tf._y = this.next_button._y + this.next_button._height + 10;
  261.       this.location_tf._width = this.next_button._x + this.next_button._width;
  262.       this.button_holder._y = this.height - this.button_holder._height - 10;
  263.       this.button_holder._x = this.uiPanelWidth / 2 - this.button_holder._width / 2;
  264.       this.load_bar._x = this.uiPanelWidth + (this.width - this.uiPanelWidth) / 2 - this.load_bar.width / 2;
  265.       this.load_bar._y = this.height / 2 - this.load_bar.height / 2;
  266.    }
  267.    function onLoadInit(target_mc)
  268.    {
  269.       trace("onLoadInit");
  270.       this.image_holder.setMask(this.mask);
  271.       this.findHotSpots(target_mc);
  272.    }
  273.    function onLoadStart(target_mc)
  274.    {
  275.    }
  276.    function onLoadError(target_mc, errorCode)
  277.    {
  278.       trace("onLoadError: " + errorCode);
  279.    }
  280.    function onLoadProgress(target_mc, loadedBytes, totalBytes)
  281.    {
  282.       this.load_bar.text = "Loading Image";
  283.       this.load_bar.percent = loadedBytes / totalBytes;
  284.    }
  285.    function onLoadComplete(target_mc)
  286.    {
  287.    }
  288. }
  289.