1 Reply Latest reply on Jan 29, 2008 7:34 PM by ntsiii

    how do I include a dynamic image that changes?

    maxrd
      I need to include a photo based on selecting a user from a datagrid - using the user id I can get the image from a url where the end path uses the userid + .jpg. All of this works for the first image but when I click on another user I get the same image as previously shown. I'm using:
      <mx:Image source="{getImage()}" /> where getImage is a function that is:
      private function studentImage():String {
      var baseurl:String = " http://nuweb.northumbria.ac.uk/photoids/";
      var studentID:String = dgStudents.selectedItem.studentid;
      var url:String = baseurl + studentID + ".jpg";
      reeturn url;
      }

      since that didn't work I tried removing the source attribute from the <mx:Image /> and instead when the user click I'm calling the same function but with a void return using the Image.load:
      private function studentImage():void {
      var baseurl:String = " http://nuweb.northumbria.ac.uk/photoids/";
      var studentID:String = dgStudents.selectedItem.studentid;
      var url:String = baseurl + studentID + ".jpg";

      var ldr:Loader = new Loader();
      var urlReq:URLRequest = new URLRequest(url);
      ldr.load(urlReq);
      imgStudentPhoto.load(ldr.content); // imgStudentPhoto is the id of the Image component
      }

      This doesn't work either - in fact whereas the first method shows an image that doesn't change this shows no image at all.

      Please, any suggestions?

      Thanks, Rob
        • 1. Re: how do I include a dynamic image that changes?
          ntsiii Level 3
          When binding to a function, there needs to be an argument to tell flex when to execute the binding.

          Or, declare a [Bindable] string var, and in a change handler, build and assign the source string to that var. Bind to the var.

          The simplest is not to bind, but to build and assign the source string in the change handler function.

          Tracy