12 Replies Latest reply on Dec 30, 2008 1:30 AM by BharathEnaganti

    Image Refresh

    GeorgeWS Level 1
      I am using Flex 2. I have a Datagrid With Cars and Vin numbers. I select a car and next to the grid and image appears. Under the image I have a browse and upload button. So a user can browse for a new image of the Car and upload the image. That part works also. After the image is uploaded I have to make a different selection and then go back to the original Car to have a the new image display. How can I refresh the selected item of the datagrid to show the new images? Thanks

        • 1. Re: Image Refresh
          rtalton Level 4
          Are you setting the image.source property after the upload?
          • 2. Re: Image Refresh
            GeorgeWS Level 1
            Im not sure sure how to do that after the upload. I am doing this to show the original image when a car is selected in the data grid:

            <mx:Image id="myImageDriver" source=" http://mysite/operations/operdata/images/Driver/{mainList.selectedItem.Vin}.jpg" maintainAspectRatio="true" height="100" width="200"/>

            So I upload my image and then want to "Refresh" the myImageDriver after upload. but do not know the syntaxt.


            • 3. Re: Image Refresh
              rtalton Level 4
              Your binding isn't working - since it is bound to the VIN and that is not changing, the image source doesn't update.
              In your upload procedure, add code to change the image source after the image is uploaded. You'll should ensure that the new image was indeed uploaded first.
              Can you post your upload code, and how you verify the file was uploaded?
              • 4. Re: Image Refresh
                GeorgeWS Level 1
                Its alot of code, I am using the code from "Multi-File Upload Component Ver 1.1 by Ryan Favro"

                I know the image gets uploaded I can see it on the server also when I make another selection in the datagrid and the reselect the car the i uploaded an image against the image refreshes and changes to the uploaded image so its pretty much working perfectly, I just want the mx:Image tag to refresh after upload. When you browse for an image and then you upload it I change the file name to the vin number. Im surprised there is no reload image command. I was thinking:

                myImageDriver.refresh() or myImageDriver.load() but no go

                • 5. Re: Image Refresh
                  ntsiii Level 3
                  I would use a function to build the image source:

                  private function getSourceUrl(sVin:String):String {
                  var sUrl:String = " http://mysite/operations/operdata/images/Driver/" + sVin + ".jpg";
                  return sUrl;

                  At least that way you will be able to debug your urls.


                  return trace
                  • 6. Re: Image Refresh
                    rtalton Level 4
                    Your image will not automatically "refresh" after you upload an image; it has no way of knowing you uploaded anything to a server. There is no "refresh" method for the Image component.
                    • 7. Re: Image Refresh
                      GeorgeWS Level 1
                      I am doing this to show it completed the upload:

                      private function completeHandler(event:Event):void{
                      if (_files.length > 0){
                      _totalbytes = 0;
                      _progressbar.label = "Uploads Complete";
                      var uploadCompleted:Event = new Event(Event.COMPLETE);

                      Im not sure what I would put to "redraw" the image.

                      Thanks for helping me

                      • 8. Re: Image Refresh
                        rtalton Level 4
                        Good, it looks like you are using a listener to handle the Event.COMPLETE event. In that handler, do this:
                        myImageDriver.source = "the path to the newly uploaded file";

                        Be aware that once you change the myImageDriver.source property, it will no longer be bound to the DataGrid, and the image won't change when you click on a DatagGrid Item. You'd have to handle that itemClick event, as well:
                        " ' http://mysite/operations/operdata/images/Driver/' + event.currentTarget.selectedItem.Vin + '.jpg' "
                        " ' http://mysite/operations/operdata/images/Driver/' + mainList.selectedItem.Vin + '.jpg' "

                        Maybe someone has a simpler suggestion...
                        • 9. Re: Image Refresh
                          GeorgeWS Level 1
                          I see what you are saying. My problem is that the path to the newly uploaded image is the same path. There can only be one image for the vin number so on the server there is a file 123456789.jpg and I go to my app and browse for new truck image and get image photo01.jpg (the new image I want to replace the old) I upload that to the server and change the name to the vin (123456789.jpg). that means the path is the same. The path only changes when there is a different selection in the DG. Mybe there is a way to deselect and selectItem again. Just thinking

                          Thanks for the help though

                          • 10. Re: Image Refresh
                            rtalton Level 4
                            If it's the same path and file name, set the source and load it in one line doing this:
                            myImageDriver.load( "the path to the newly uploaded file");
                            This will force it to load.

                            You could get tricky and just try:
                            ..since the source hasn't actually been changed. This will re-load the same file, and the binding expression will not change.
                            Try it and see if that works.

                            Hope this helps.
                            • 11. Re: Image Refresh
                              GeorgeWS Level 1

                              Perfection, Thanks Alot.

                              • 12. Image Refresh

                                I am trying to upload image.Getting some errors.If you don't mind will you send me code for that if you are doing without using java or php.
                                this is my mail id baratenaganti@gmail.com