0

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.

Bridget
  • 21
  • 4

2 Answers2

0

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
  • 6,237
  • 1
  • 19
  • 36
  • Neither of these would dynamically refresh the image either. – Bridget Apr 26 '10 at 14:14
  • 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 Apr 26 '10 at 14:42
  • 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 Apr 26 '10 at 15:57
0

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

michael
  • 1,160
  • 7
  • 19
  • What is the purpose to use the Tile tag? You want to show one image or a batch of images? – michael Apr 26 '10 at 15:00
  • Sorry, I am misunderstanding your question before. Are you receiving the last image only? – michael Apr 26 '10 at 17:08
  • 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 Apr 26 '10 at 17:32
  • Have you tried the Repeater inside the Tile. Maybe, it is much more easiler. – michael Apr 27 '10 at 00:30
  • 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 Apr 27 '10 at 12:37