home *** CD-ROM | disk | FTP | other *** search
/ Kellogg's Art Attack / ArtAttack04_Building.iso / data1.cab / Showme / instructions.swf / scripts / frame_1 / DoAction.as
Text File  |  2006-04-28  |  6KB  |  273 lines

  1. function init(screen)
  2. {
  3.    screenRef = screen;
  4.    discNum = Number(screenRef.charAt(1));
  5.    xmlData.load("data.xml");
  6.    reset();
  7.    holder_mc._xscale = 70;
  8.    holder_mc._yscale = 70;
  9. }
  10. function promptNextPart()
  11. {
  12.    trace("animate button: btn" + Number(curPart + 1));
  13.    this["btn" + (curPart + 1)].gotoAndPlay("prompt");
  14.    this["btn" + (curPart + 1)].isPrompting = true;
  15. }
  16. function loadPart()
  17. {
  18.    if(curPart < 10)
  19.    {
  20.       trace("loading: " + aAnim.attributes.id + "_0" + curPart);
  21.       loader.loadClip(swfPath + aAnim.attributes.id + "_0" + curPart + ".swf",holder_mc);
  22.    }
  23.    else
  24.    {
  25.       trace("loading: " + aAnim.attributes.id + "_" + curPart);
  26.       loader.loadClip(swfPath + aAnim.attributes.id + "_" + curPart + ".swf",holder_mc);
  27.    }
  28. }
  29. function setButtons()
  30. {
  31.    if(numParts > 1)
  32.    {
  33.       i = 1;
  34.       while(i <= numParts)
  35.       {
  36.          this["btn" + i]._visible = true;
  37.          this["btn" + i].myText.gotoAndStop(i);
  38.          i++;
  39.       }
  40.    }
  41. }
  42. function resetButtons()
  43. {
  44.    i = 1;
  45.    while(i <= 8)
  46.    {
  47.       this["btn" + i].gotoAndStop(1);
  48.       i++;
  49.    }
  50. }
  51. function reset()
  52. {
  53.    curPart = 1;
  54.    i = 1;
  55.    while(i <= 8)
  56.    {
  57.       this["btn" + i]._visible = false;
  58.       i++;
  59.    }
  60. }
  61. function togglePlaying()
  62. {
  63.    if(isPlaying)
  64.    {
  65.       isPlaying = false;
  66.       holder_mc.stop();
  67.       playpause_btn.gotoAndStop("pause_n");
  68.    }
  69.    else
  70.    {
  71.       isPlaying = true;
  72.       if(isEnded)
  73.       {
  74.          playAnim();
  75.       }
  76.       else
  77.       {
  78.          holder_mc.play();
  79.       }
  80.       playpause_btn.gotoAndStop("play_n");
  81.    }
  82. }
  83. function playAnim()
  84. {
  85.    playpause_btn.gotoAndStop("play_n");
  86.    isPlaying = true;
  87.    isEnded = false;
  88.    holder_mc.onEnterFrame = function()
  89.    {
  90.       if(this._currentframe == this._totalframes)
  91.       {
  92.          this.stop();
  93.          delete this.onEnterFrame;
  94.          isPlaying = false;
  95.          isEnded = true;
  96.          playpause_btn.gotoAndStop("pause_n");
  97.          promptNextPart();
  98.       }
  99.    };
  100.    part_txt.text = "Part " + curPart + " of " + numParts;
  101.    holder_mc.play();
  102. }
  103. function stopRewind()
  104. {
  105.    rewinding = false;
  106.    trace("rewind stopped");
  107.    clearInterval(intervalID);
  108. }
  109. function showTooltip(tip, button)
  110. {
  111.    trace(tip);
  112.    clearInterval(tooltipInterval);
  113.    tooltip_mc.text_txt.text = tip;
  114.    tooltip_mc.bg._width = tooltip_mc.text_txt._width + 10;
  115.    tooltip_mc._x = button._x;
  116.    tooltip_mc.bg._x = - tooltip_mc.bg._width / 2;
  117. }
  118. var discNum;
  119. var screenRef;
  120. var swfPath;
  121. var curPart;
  122. var xmlData = new XML();
  123. var aCD = new Array();
  124. var aAnim = new Array();
  125. var numParts;
  126. var loader = new MovieClipLoader();
  127. var listener = new Object();
  128. var isPlaying;
  129. var isEnded;
  130. var rewinding = false;
  131. var intervalID;
  132. var tooltipInterval;
  133. var tooltipDelay = 0.5;
  134. var rewindCount;
  135. loader.addListener(listener);
  136. xmlData.ignoreWhite = true;
  137. listener.onLoadInit = function()
  138. {
  139.    trace("loaded!");
  140.    playAnim();
  141. };
  142. restart_btn.onRollOver = function()
  143. {
  144.    tooltipInterval = setInterval(showTooltip,tooltipDelay * 1000,"Back to Start",this);
  145.    this.gotoAndStop(2);
  146. };
  147. restart_btn.onRollOut = restart_btn.onDragOut = function()
  148. {
  149.    this.gotoAndStop(1);
  150.    clearInterval(tooltipInterval);
  151.    tooltip_mc._x = -100;
  152. };
  153. restart_btn.onPress = function()
  154. {
  155.    curPart = 1;
  156.    loadPart();
  157.    clearInterval(tooltipInterval);
  158.    tooltip_mc._x = -100;
  159. };
  160. rewind_btn.onRollOver = function()
  161. {
  162.    tooltipInterval = setInterval(showTooltip,tooltipDelay * 1000,"Back",this);
  163.    this.gotoAndStop(2);
  164. };
  165. rewind_btn.onRollOut = rewind_btn.onDragOut = function()
  166. {
  167.    this.gotoAndStop(1);
  168.    clearInterval(tooltipInterval);
  169.    tooltip_mc._x = -100;
  170. };
  171. rewind_btn.onPress = function()
  172. {
  173.    if(!rewinding)
  174.    {
  175.       rewinding = true;
  176.       intervalID = setInterval(stopRewind,500);
  177.       holder_mc.gotoAndStop(1);
  178.       togglePlaying();
  179.    }
  180.    else
  181.    {
  182.       clearInterval(intervalID);
  183.       rewinding = false;
  184.       if(curPart > 1)
  185.       {
  186.          curPart--;
  187.          loadPart();
  188.       }
  189.    }
  190.    clearInterval(tooltipInterval);
  191.    tooltip_mc._x = -100;
  192. };
  193. playpause_btn.onRollOver = function()
  194. {
  195.    tooltipInterval = setInterval(showTooltip,tooltipDelay * 1000,"Play/Pause",this);
  196.    if(isPlaying)
  197.    {
  198.       this.gotoAndStop("play_r");
  199.    }
  200.    else
  201.    {
  202.       this.gotoAndStop("pause_r");
  203.    }
  204. };
  205. playpause_btn.onRollOut = playpause_btn.onDragOut = function()
  206. {
  207.    if(isPlaying)
  208.    {
  209.       this.gotoAndStop("play_n");
  210.    }
  211.    else
  212.    {
  213.       this.gotoAndStop("pause_n");
  214.    }
  215.    clearInterval(tooltipInterval);
  216.    tooltip_mc._x = -100;
  217. };
  218. playpause_btn.onPress = function()
  219. {
  220.    togglePlaying();
  221.    clearInterval(tooltipInterval);
  222.    tooltip_mc._x = -100;
  223. };
  224. fastforward_btn.onRollOver = function()
  225. {
  226.    tooltipInterval = setInterval(showTooltip,tooltipDelay * 1000,"Forward",this);
  227.    this.gotoAndStop(2);
  228. };
  229. fastforward_btn.onRollOut = fastforward_btn.onDragOut = function()
  230. {
  231.    this.gotoAndStop(1);
  232.    clearInterval(tooltipInterval);
  233.    tooltip_mc._x = -100;
  234. };
  235. fastforward_btn.onPress = function()
  236. {
  237.    if(numParts != curPart)
  238.    {
  239.       curPart++;
  240.       loadPart();
  241.    }
  242.    clearInterval(tooltipInterval);
  243.    tooltip_mc._x = -100;
  244. };
  245. xmlData.onLoad = function(success)
  246. {
  247.    if(success)
  248.    {
  249.       aCD = xmlData.firstChild.childNodes[discNum - 1].childNodes;
  250.       i = 0;
  251.       while(i < aCD.length)
  252.       {
  253.          if(aCD[i].attributes.id == screenRef)
  254.          {
  255.             aAnim = aCD[i];
  256.          }
  257.          i++;
  258.       }
  259.       swfPath = xmlData.firstChild.attributes.swfPath;
  260.       numParts = aAnim.attributes.numParts;
  261.       trace("animation: " + aAnim.attributes.title);
  262.       trace("number of parts: " + numParts);
  263.       if(numParts == 1)
  264.       {
  265.          fastforward_btn._visible = false;
  266.          restart_btn._visible = false;
  267.       }
  268.       setButtons();
  269.       loadPart();
  270.    }
  271. };
  272. tooltip_mc.text_txt.autoSize = "center";
  273.