Chumby Webcam Image Cycling


Sample Actionscript for showing 4 webcams on a single Chumby display and cycling through 9 webcams. Every second replacing one of the images with the next one in the sequence.

<br />
class CamView.Main {&lt;br&gt;<br />
  static var urls:Array = [&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam1.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam2.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam3.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam4.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam5.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam6.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam7.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam8.jpg&quot;,&lt;br&gt;<br />
  &quot;http://192.168.2.10/cam9.jpg&quot; ];&lt;br&gt;<br />
  static var numurls = 9;&lt;br&gt;<br />
  private var parent:MovieClip;&lt;br&gt;<br />
  private var tf:TextField;&lt;br&gt;<br />
  private var mcTL:MovieClip;&lt;br&gt;<br />
  private var mcTR:MovieClip;&lt;br&gt;<br />
  private var mcBL:MovieClip;&lt;br&gt;<br />
  private var mcBR:MovieClip;&lt;br&gt;<br />
  static var count:Number = 0;&lt;br&gt;<br />
  static var urlidx:Number = 4;</p>
<p>  function UpdateText(mc:MovieClip) {&lt;br&gt;<br />
    // Add time based url extension to force non cached images&lt;br&gt;<br />
    var time:Date = new Date();&lt;br&gt;<br />
    var sec:String = String(time.getSeconds());&lt;br&gt;<br />
    var cnt:String = String(time.getMinutes()) + sec;&lt;br&gt;<br />
    var urlext:String = &quot;?t=&quot; + cnt;</p>
<p>    var mlMyLoader:MovieClipLoader = new MovieClipLoader();</p>
<p>    // rotate images and urls&lt;br&gt;<br />
    switch (count) {&lt;br&gt;<br />
      case 0: mlMyLoader.loadClip(urls[urlidx] + urlext, &quot;mCam1&quot;); break;&lt;br&gt;<br />
      case 1: mlMyLoader.loadClip(urls[urlidx] + urlext, &quot;mCam2&quot;); break;&lt;br&gt;<br />
      case 3: mlMyLoader.loadClip(urls[urlidx] + urlext, &quot;mCam3&quot;); break;&lt;br&gt;<br />
      case 2: mlMyLoader.loadClip(urls[urlidx] + urlext, &quot;mCam4&quot;); break;&lt;br&gt;<br />
    }&lt;br&gt;</p>
<p>    if (++count == 4) count = 0;&lt;br&gt;<br />
    if (++urlidx == numurls) urlidx = 0;</p>
<p>    delete mlMyLoader;&lt;br&gt;<br />
  }</p>
<p>  function Main(mc:MovieClip) {&lt;br&gt;<br />
    // save reference to main movieclip&lt;br&gt;<br />
    this.parent = mc;</p>
<p>    var mlMyLoader:MovieClipLoader = new MovieClipLoader();</p>
<p>    mcTL = mc.createEmptyMovieClip(&quot;mCam1&quot;, mc.getNextHighestDepth());&lt;br&gt;<br />
    mcTR = mc.createEmptyMovieClip(&quot;mCam2&quot;, mc.getNextHighestDepth());&lt;br&gt;<br />
    mcBL = mc.createEmptyMovieClip(&quot;mCam3&quot;, mc.getNextHighestDepth());&lt;br&gt;<br />
    mcBR = mc.createEmptyMovieClip(&quot;mCam4&quot;, mc.getNextHighestDepth());&lt;/p&gt;</p>
<p>    // assume cam images are 640x480, scale by 1/4 for Chumby display&lt;br&gt;<br />
    mcTL._xscale = 25;&lt;br&gt;<br />
    mcTL._yscale = 25;&lt;br&gt;<br />
    mlMyLoader.loadClip(urls[0], &quot;mCam1&quot;);</p>
<p>    mcTR._x = 160;&lt;br&gt;<br />
    mcTR._xscale = 25;&lt;br&gt;<br />
    mcTR._yscale = 25;&lt;br&gt;<br />
    mlMyLoader.loadClip(urls[1], &quot;mCam2&quot;);</p>
<p>    mcBL._y = 120;&lt;br&gt;<br />
    mcBL._xscale = 25;&lt;br&gt;<br />
    mcBL._yscale = 25;&lt;br&gt;<br />
    mlMyLoader.loadClip(urls[2], &quot;mCam3&quot;);</p>
<p>    mcBR._x = 160;&lt;br&gt;<br />
    mcBR._y = 120;&lt;br&gt;<br />
    mcBR._xscale = 25;&lt;br&gt;<br />
    mcBR._yscale = 25;&lt;br&gt;<br />
    mlMyLoader.loadClip(urls[3], &quot;mCam4&quot;);</p>
<p>    delete mlMyLoader;</p>
<p>    var mytimer = setInterval(UpdateText, 1000, mc);<br />
  }</p>
<p>  static function main(mc:MovieClip) {&lt;br&gt;<br />
    var app = new Main(mc);&lt;br&gt;<br />
  }&lt;br&gt;<br />
}&lt;br&gt;<br />