views:

442

answers:

2

I am writing a Flex application to receive xml from an httpservice. That works because I can populate a datagrid with the information. The xml sends image pathnames. A combobox sends a new HttpService call onChange. This repopulates the datagrid and puts new images in the folder that flex is accessing.

I want to dynamically change the image without changing the pathname of the image.

<mx:Canvas id="borderCanvas"><mx:Canvas id="dropCanvas">
  <mx:Tile id="adTile"><mx:Image></mx:Image>
  </mx:Tile></mx:Canvas></mx:Canvas>

This is my component. I assign my Image sources using this code:

var i:Number = 0;
      while ( i <= dg_conads.rowCount){
        var img:Image = new Image();
        img.source = null;
        img.source = imageSource+i+".jpg";
        adTile.addChild(img);
        i++; }

My biggest problem is that the images are not refreshing. I get the same image even though I've prevented caching from the HTML wrapper and the ASP.Net website. The image automatically loads in the folder and refreshes in the folder but I can't get the image to refresh in the application. I've tried removeAllChildren(); delete(adTile.getChildAt(0)); and neither worked.

A: 

I would try using:

img.load(imageSource + i + ".jpg");

If that doesn't work, try appending a random number on the end ie:

img.source = imageSource + i + ".jpg?" + Math.random();
quoo
Neither of these would dynamically refresh the image either.
Bridget
Oh, how are you notifying the flex application that the image has changed? Flex won't monitor the image to see if it's changed.
quoo
I guess I haven't notified that it has changed, that's what I need to do for a refresh, I am just trying to remove all references and delete the image and then create a new one. Do you have a way to notify flex?
Bridget
A: 

Have you tried to add id="img" into the mx:Image tag directly and remove adTile.addChild(img); in the script?

michael
I did try that. It didn't work
Bridget
What is the purpose to use the Tile tag? You want to show one image or a batch of images?
michael
a batch of images.
Bridget
Sorry, I am misunderstanding your question before.Are you receiving the last image only?
michael
i recieve the first image, then when i call the webservice again and the flex runs through the result event function to reassign the source to the images, the images won't refresh to the new image in the folder (the name of the image doesn't change, just the actual picture itself)
Bridget
Have you tried the Repeater inside the Tile. Maybe, it is much more easiler.
michael
yes it still will not change the image content once it recognizes a filename. I'm changing the application so my webservice will generate unique filenames and pass those paths to flex.
Bridget