PDA

View Full Version : image refresh


shree123
05-08-2007, 04:09 AM
hi guys i ahve writtent some code to display the latest image rom ipcamer a in flex2 mxml application i still have a flickering problem.please help me

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" cachePolicy="auto">
<mx:Script>
<![CDATA[
import flash.utils.setInterval;
import flash.utils.setTimeout;
private function afterImage():void
{
image1.load("http://192.168.1.68/Jpeg/CamImg.jpg");
}
]]>
</mx:Script>
<mx:Canvas>
<mx:Image id="image1" initialize="setInterval(afterImage,10000);" source="http://192.168.1.68/Jpeg/CamImg.jpg">
</mx:Image>
</mx:Canvas>
</mx:Application>

neerfri
05-20-2007, 01:41 PM
Hi shree123,
I think a possible solution to your problem will be to load the image from the web to a different Image object and then swap the display, something like:


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" cachePolicy="auto">
<mx:Script>
<![CDATA[
import flash.utils.setInterval;
import flash.utils.setTimeout;

private var currentImage:int=0;

private function afterImage():void
{
if (currentImage == 0)
{
image1.addEventListener(Event.COMPLETE,swapImages) ;
image1.addEventListener(Event.COMPLETE,swapImages) ;
image1.load("http://192.168.1.68/Jpeg/CamImg.jpg");
} else {
image0.load("http://192.168.1.68/Jpeg/CamImg.jpg");
}
}

private function swapImages(event:Event):void
{
if (currentImage == 0)
{
image1.visible = true;
image0.visible = false;
} else {
image0.visible = false;
image1.visible = true;
}
}
]]>
</mx:Script>
<mx:Canvas>
<mx:Image id="image0" initialize="setInterval(afterImage,10000);" source="http://192.168.1.68/Jpeg/CamImg.jpg">
<mx:Image id="image1" visible="false">
</mx:Image>
</mx:Canvas>
</mx:Application>


I didn't try it but I think it should work...

Have fun !!!
neerfri

dbedient
06-01-2007, 03:22 PM
shree123 - did you ever figure out the flicker. I tested the example above and still had the same problem. I think the idea is right there's just something missing.

Thanks in advance for any help!
Doug

glnsagar
04-30-2008, 08:13 PM
Did you guys get this solved?

glnsagar
05-02-2008, 12:03 AM
I'm newbie. So correct me if the code is wrong or not efficient.

But, this thing works fine for me.

...........
private static var count = 0;
...........
function setup(){
var my_mcl:MovieClipLoader = new MovieClipLoader();
var img_mc_0:MovieClip = _root.createEmptyMovieClip("img_mc_0", 10);
var img_mc_1:MovieClip = _root.createEmptyMovieClip("img_mc_1", 20);
..............
setInterval(updateScreen, 500, my_mcl, img_mc_0, img_mc_1);
}

function updateScreen(my_mcl, img_mc_0, img_mc_1){
if ((count % 2) == 0)
my_mcl.loadClip(_currentCamURL, img_mc_0);
else
my_mcl.loadClip(_currentCamURL, img_mc_1);

count++;
}