10 Replies Latest reply on Jan 30, 2009 2:29 PM by jdb1a1

    Problems with Loader, BitmapData, or possibly URLRequest

    jdb1a1
      Hi,

      I am having an issue requesting jpegs from my localhost and placing in my array. Let me explain a little bit: I am trying to devise an image gallery of sorts, with the thumbnails of 6 different images. I have images on localhost.

      I wrote a new class which, simply takes in an image path identifier string, builds a new string to the path of the image, gives it to a URLRequest, then a Loader object loads that URLRequest. Then I create a BitmapData object which, after calling the .draw(loader) method, gets my BitmapData, which i give to a Bitmap and then finally I set it to the source of an image object. Then I give this image to an array until I have loaded a maximum of 6 images to the array. These are thumbnail images, 150 x 113, and I have got 6 of them.

      When I try to use the image in and of itself, i get nothing. When I try to pass the .width and .height properties of the loader object to the BitmapData object, I get an error that says "Argument Error: Invalid BitmapData." When I give the BitmapData constructor a specific height and width, 150 for both, the "Invalid BitmapData" error goes away, but I cannot find any content in the images that returns from my custom class. I was able to load an image once using this method, but I have been having issues ever since.

      When I trace the array I get back, it says that I have six image objects in my array, so I know the problem has to be in how I convert the loader to an image.

      I can access all of my images through Firefox.

      I know that the issue isn't with the array or even specifically in my class, so I will post what I believe to be the relevant parts of my code. If somebody could take a look at it and help me out, it would be VERY much appreciated!

      Thanks,
      Jeremy
        • 1. Re: Problems with Loader, BitmapData, or possibly URLRequest
          Level 7

          "jdb1a1" <webforumsuser@macromedia.com> wrote in message
          news:glt5u0$5g8$1@forums.macromedia.com...
          > Hi,
          >
          > I am having an issue requesting jpegs from my localhost and placing in my
          > array. Let me explain a little bit: I am trying to devise an image
          > gallery of
          > sorts, with the thumbnails of 6 different images. I have images on
          > localhost.
          >
          > I wrote a new class which, simply takes in an image path identifier
          > string,
          > builds a new string to the path of the image, gives it to a URLRequest,
          > then a
          > Loader object loads that URLRequest. Then I create a BitmapData object
          > which,
          > after calling the .draw(loader) method, gets my BitmapData, which i give
          > to a
          > Bitmap and then finally I set it to the source of an image object. Then I
          > give
          > this image to an array until I have loaded a maximum of 6 images to the
          > array.
          > These are thumbnail images, 150 x 113, and I have got 6 of them.
          >
          > When I try to use the image in and of itself, i get nothing. When I try
          > to
          > pass the .width and .height properties of the loader object to the
          > BitmapData
          > object, I get an error that says "Argument Error: Invalid BitmapData."
          > When I
          > give the BitmapData constructor a specific height and width, 150 for both,
          > the
          > "Invalid BitmapData" error goes away, but I cannot find any content in the
          > images that returns from my custom class. I was able to load an image
          > once
          > using this method, but I have been having issues ever since.
          >
          > When I trace the array I get back, it says that I have six image objects
          > in my
          > array, so I know the problem has to be in how I convert the loader to an
          > image.
          >
          > I can access all of my images through Firefox.
          >
          > I know that the issue isn't with the array or even specifically in my
          > class,
          > so I will post what I believe to be the relevant parts of my code. If
          > somebody
          > could take a look at it and help me out, it would be VERY much
          > appreciated!

          You have to wait until the loader has loaded the image before trying to get
          the BitmapData from it or the width or height.

          HTH;

          Amy


          • 2. Re: Problems with Loader, BitmapData, or possibly URLRequest
            jdb1a1 Level 1
            Thanks, Amy! I shall have to work something out with the eventListener and such. I appreciate the response!
            • 3. Re: Problems with Loader, BitmapData, or possibly URLRequest
              Level 7

              "jdb1a1" <webforumsuser@macromedia.com> wrote in message
              news:glt933$97l$1@forums.macromedia.com...
              > Thanks, Amy! I shall have to work something out with the eventListener
              > and such. I appreciate the response!

              You're welcome. I have code on my other computer that I will try to dig out
              for you tomorrow.


              • 4. Re: Problems with Loader, BitmapData, or possibly URLRequest
                jdb1a1 Level 1


                Thanks! I would really appreciate it.
                • 5. Re: Problems with Loader, BitmapData, or possibly URLRequest
                  Level 7

                  "jdb1a1" <webforumsuser@macromedia.com> wrote in message
                  news:glv1m8$fe6$1@forums.macromedia.com...
                  >
                  >
                  > Thanks! I would really appreciate it.

                  This is timeline code from a Flash movie, so you'll probably need to adjust
                  it for Flex:

                  import flash.events.Event;

                  var imgLoader:Loader = new Loader();
                  imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
                  getLoaderContents);
                  imgLoader.load(new URLRequest('projectPhotos/BoerXGoats.jpg'));
                  imgLoader.x = 10;
                  imgLoader.y = 10;
                  addChild(imgLoader);

                  function getLoaderContents(e:Event){
                  var loader:Loader = Loader(e.target.loader);
                  var image:Bitmap = new Bitmap(Bitmap(loader.content).bitmapData.clone());
                  addChild(image);
                  image.x = 200;
                  image.y = 200;
                  trace('hi');
                  }

                  This results in two copies of the same image, offset by 190 px.


                  • 7. Re: Problems with Loader, BitmapData, or possibly URLRequest
                    jdb1a1 Level 1
                    What is the best way to give the image to an array, and push that back to the mxml component that calls it? I have tried returning the array from the main method, and I have tried giving the array from a specific method which only returns the class-level array variable that I give the images too. In both cases, this happens too soon, and the array has nothing. I tried doing a while loop, incrementing in the eventHandler and then returning it from the original method, and I got an timeout error.

                    Is there a good way to do this, or am I better off pursuing another route where i store the images on my server and load them at run-time?

                    Thanks for all the help,
                    Jeremy
                    • 8. Re: Problems with Loader, BitmapData, or possibly URLRequest
                      jdb1a1 Level 1
                      Never mind; I am just going to take another approach with this.

                      thanks for all the help!

                      Jeremy
                      • 9. Re: Problems with Loader, BitmapData, or possibly URLRequest
                        Level 7

                        "jdb1a1" <webforumsuser@macromedia.com> wrote in message
                        news:glvp9r$ek9$1@forums.macromedia.com...
                        > What is the best way to give the image to an array, and push that back to
                        > the
                        > mxml component that calls it? I have tried returning the array from the
                        > main
                        > method, and I have tried giving the array from a specific method which
                        > only
                        > returns the class-level array variable that I give the images too. In
                        > both
                        > cases, this happens too soon, and the array has nothing. I tried doing a
                        > while
                        > loop, incrementing in the eventHandler and then returning it from the
                        > original
                        > method, and I got an timeout error.
                        >
                        > Is there a good way to do this, or am I better off pursuing another route
                        > where i store the images on my server and load them at run-time?

                        Either way, you're loading external images at runtime.

                        I can dig out a more recent version of the code that loads the images to an
                        Array. I'm working on a thumbnail viewing flash component, and I've stored
                        out a bunch of versions because I may one day want to teach this material as
                        a course.



                        • 10. Re: Problems with Loader, BitmapData, or possibly URLRequest
                          jdb1a1 Level 1
                          I would like to see that, if you have the time to find it.