home *** CD-ROM | disk | FTP | other *** search
/ Computer Arts 147 / Arts147.mdf / pc / CA.swf / scripts / DefineSprite_129 / frame_1 / DoAction.as
Encoding:
Text File  |  2008-01-01  |  5.3 KB  |  174 lines

  1. function movePlayhead()
  2. {
  3.    if(myVideoPlayer.state == "playing")
  4.    {
  5.       pc = myVideoPlayer.playheadTime / myVideoPlayer.totalTime;
  6.       dragBar.dragger._x = - dragBar.bar._width + dragBar.bar._width * pc;
  7.    }
  8. }
  9. function setVideoSize()
  10. {
  11.    trace("SET VIDEO SIZE CALLED ==-================");
  12.    vOff = 0;
  13.    hOff = 0;
  14.    viewAspect = 1.3333333333333333;
  15.    ht = myVideoPlayer.metadata.height;
  16.    wd = myVideoPlayer.metadata.width;
  17.    if(wd > ht)
  18.    {
  19.       ratio = 320 / wd;
  20.       vidAspect = ht / wd;
  21.       vidWidth = wd * ratio;
  22.       vidHeight = vidWidth * vidAspect;
  23.       vOff = (240 - vidHeight) / 2;
  24.       if(vidHeight > 240)
  25.       {
  26.          ratio = 240 / ht;
  27.          vidHeight = ht * ratio;
  28.          vidWidth = wd * ratio;
  29.          vOff = 0;
  30.          hOff = (320 - vidWidth) / 2;
  31.       }
  32.    }
  33.    else
  34.    {
  35.       ratio = 240 / ht;
  36.       vidAspect = wd / ht;
  37.       vidWidth = 320 * vidAspect;
  38.       vidHeight = 240;
  39.       hOff = (320 - vidWidth) / 2;
  40.    }
  41.    trace("Scale Ratio: " + ratio + " Video Aspect: " + vidAspect);
  42.    myVideoPlayer._width = vidWidth;
  43.    myVideoPlayer._height = vidHeight;
  44.    myVideoPlayer._x = hOff;
  45.    myVideoPlayer._y = vOff;
  46.    trace(vOff + "   " + hOff);
  47.    trace("Height is " + myVideoPlayer.metadata.height);
  48.    trace("Width is " + myVideoPlayer.metadata.width);
  49.    trace("Duration is " + myVideoPlayer.metadata.duration + " seconds");
  50.    videoSizeSet = true;
  51. }
  52. function setVideoLabels(num)
  53. {
  54.    numVids = _root.videoResourceList.length;
  55.    p = 0;
  56.    while(p < selectorButtons.length)
  57.    {
  58.       selectorButtons[p]._visible = false;
  59.       p++;
  60.    }
  61.    i = 0;
  62.    while(i < _root.videoResourceList.length)
  63.    {
  64.       trace("setting video selector " + _root.videoResourceList[i]);
  65.       vidName = _root.videoResourceList[i];
  66.       vidName = vidName.slice(0,-4);
  67.       selectorButtons[i].vidName = vidName;
  68.       selectorButtons[i]._visible = true;
  69.       i++;
  70.    }
  71. }
  72. function setContentPath(path)
  73. {
  74.    videoSizeSet = false;
  75.    trace("setting SMALL contentPath to:" + path + "|");
  76.    tPath = path;
  77.    myVideoPlayer.load(tPath);
  78.    trace("contentPath is now " + myVideoPlayer.contentPath);
  79.    myVideoPlayer.rewind();
  80.    myVideoPlayer.play();
  81. }
  82. stop();
  83. var videoSizeSet = false;
  84. var selectorButtons = Array(videoSelector.vidButton1,videoSelector.vidButton2,videoSelector.vidButton3,videoSelector.vidButton4,videoSelector.vidButton5,videoSelector.vidButton6,videoSelector.vidButton7,videoSelector.vidButton8,videoSelector.vidButton9);
  85. myVideoPlayer.playPauseButton = myPlayButton;
  86. myVideoPlayer.backButton = myBackButton;
  87. trace("initialising video player");
  88. MovieClip(myVideoPlayer.getVideoPlayer(myVideoPlayer.activeVideoPlayerIndex))._video.smoothing = true;
  89. videoSelector._visible = false;
  90. var listenerObject = new Object();
  91. listenerObject.stateChange = function(eventObject)
  92. {
  93.    trace(myVideoPlayer.state + ": playhead time is: " + myVideoPlayer.playheadTime);
  94.    if(myVideoPlayer.state == "playing")
  95.    {
  96.       if(!videoSizeSet)
  97.       {
  98.          setVideoSize();
  99.       }
  100.       _root.flvPlaying = true;
  101.    }
  102.    else
  103.    {
  104.       _root.flvPlaying = false;
  105.    }
  106.    if(myVideoPlayer.state == "buffering")
  107.    {
  108.       trace("buffering");
  109.       trace("w=" + myVideoPlayer.metadata.width + " h=" + myVideoPlayer.metadata.height);
  110.    }
  111. };
  112. myVideoPlayer.addEventListener("stateChange",listenerObject);
  113. var progressObject = new Object();
  114. progressObject.progress = function(eventObject)
  115. {
  116.    if(myVideoPlayer.metadataLoaded)
  117.    {
  118.       vOff = 0;
  119.       hOff = 0;
  120.       viewAspect = 1.3333333333333333;
  121.       ht = myVideoPlayer.metadata.height;
  122.       wd = myVideoPlayer.metadata.width;
  123.       if(wd > ht)
  124.       {
  125.          ratio = 320 / wd;
  126.          vidAspect = ht / wd;
  127.          vidWidth = wd * ratio;
  128.          vidHeight = vidWidth * vidAspect;
  129.          vOff = (240 - vidHeight) / 2;
  130.          if(vidHeight > 240)
  131.          {
  132.             ratio = 240 / ht;
  133.             vidHeight = ht * ratio;
  134.             vidWidth = wd * ratio;
  135.             vOff = 0;
  136.             hOff = (320 - vidWidth) / 2;
  137.          }
  138.       }
  139.       else
  140.       {
  141.          ratio = 240 / ht;
  142.          vidAspect = wd / ht;
  143.          vidWidth = 320 * vidAspect;
  144.          vidHeight = 240;
  145.          hOff = (320 - vidWidth) / 2;
  146.       }
  147.       trace("Scale Ratio: " + ratio + " Video Aspect: " + vidAspect);
  148.       myVideoPlayer._width = vidWidth;
  149.       myVideoPlayer._height = vidHeight;
  150.       myVideoPlayer._x = hOff;
  151.       myVideoPlayer._y = vOff;
  152.       trace(vOff + "   " + hOff);
  153.       trace("Height is " + myVideoPlayer.metadata.height);
  154.       trace("Width is " + myVideoPlayer.metadata.width);
  155.       trace("Duration is " + myVideoPlayer.metadata.duration + " seconds");
  156.    }
  157. };
  158. myVideoPlayer.addEventListener("progress",progressObject);
  159. dragBar.dragger.onPress = function()
  160. {
  161.    myVideoPlayer.pause();
  162.    startDrag(dragBar.dragger,0,dragBar.bar._x - dragBar.bar._width,dragBar.bar._y,dragBar.bar._x,dragBar.bar._y);
  163. };
  164. dragBar.dragger.onRelease = function()
  165. {
  166.    trace("settingplayhead");
  167.    pc = 1 + dragBar.dragger._x / dragBar.bar._width;
  168.    myVideoPlayer.playheadTime = myVideoPlayer.totalTime * pc;
  169.    myVideoPlayer.play();
  170.    stopDrag();
  171. };
  172. dragBar.dragger.onReleaseOutside = dragBar.dragger.onRelease;
  173. playHeadMover = setInterval(movePlayhead,20,0);
  174.