1 Reply Latest reply on Feb 18, 2008 1:12 PM by Nathanael86

    Periodically Update Image

    Nathanael86
      Hi all!

      I'm writing a quick web application to display a set of images from a server. The images on the server will be periodically updated, but retain the same name.

      The flex app should periodically reload the images from the server. I tried writing a timer in AS 3.0 to call Image.load, but this didn't update the images. Maybe because they're being cached?

      Here's what I tried, but what's the best way to do this in flex? I'm brand new to flex but not to actionscript.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="horizontal" verticalScrollPolicy="off">

      <mx:Script>
      <![CDATA[
      import mx.controls.Image;

      private var interval:uint;
      private var streaming:Boolean = false;

      private function startStream():void
      {
      if (!streaming)
      {
      btnStart.label = "Stop";
      interval = setInterval(refreshImages, 5000);
      }
      else
      {
      btnStart.label = "Start";
      clearInterval(interval);
      }

      streaming = !streaming;
      }

      private function refreshImages():void
      {
      trace("refreshImages()");

      i1.load(" http://sptest1xp/Agenda/MiniView/TestImages/m0.png");
      i2.load(" http://sptest1xp/Agenda/MiniView/TestImages/m1.png");
      i3.load(" http://sptest1xp/Agenda/MiniView/TestImages/m2.png");
      }

      ]]>
      </mx:Script>



      <mx:Panel id="panelImages" width="620" height="220"
      layout="horizontal" horizontalScrollPolicy="off"
      verticalScrollPolicy="off"
      title="Mini View Web Edition" horizontalAlign="left">

      <mx:Image i0/>
      <mx:Image i1/>
      <mx:Image i2/>

      <mx:ControlBar width="100%">
      <mx:Spacer width="100%"/>
      <mx:Button id="btnStart" label="Start" click="startStream();"/>
      </mx:ControlBar>
      </mx:Panel>

      </mx:Application>