Search code examples
actionscript-3flashactionscript-2

Dynamic changing picture in ActionScript 3 without flickering


I want to have a image in my Flash file which can be changed from another program.

In ActionScript 2 I used a Loader, set the contentPath and made a Motiontween in the Timeline this worked very well.

But now in Actionscript 3 I do the same, I use the UILoader, I set the source and create a Motiontween but now the image disappears for a short time, everytime the Tween starts over again.

Is there a way to do this properly?

My code right now:

var myXML:XML;
var myLoader:URLLoader = new URLLoader();

var text:String;
var imagePath:String;

myLoader.load(new URLRequest("C:/Flash/paths.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void
{       
    myXML = new XML(e.target.data);

    text = myXML.text;
    imagePath = myXML.path;

    TextContainer.text = team1name;
    imageContainer.source = team2logoPath;

    trace("trace");    
}

The text isn't flickering but the image is, so I don't think the XML Loader is the reason that it works with and not with AS3.

Even if I only change the source of the image every time, the image gets invisible for a short time:

imageContainer.source = "C:/images/no_image.png";

Solution

  • OK the flickering you are getting is the load time it takes to download the image or in the 3sample you provided loading the image from disk. If you want to avoid this you need to preload the image in one way or another.
    You find an open source preload easy. What I would do is create an array of image containers and just remove current element from stage and then add the next one in the array when you want to change images.
    With this method you will assign the source to the item and it will download it even if it is not being displayed.