4 Replies Latest reply on Mar 29, 2010 9:30 PM by real_ideveloper

    Image width on adding


      Hi all.



      I would like to know how i can figure out the width of an image after adding it to the canvas.


      I was trying to call the width getter method, but it returned 0.


      I could get width with the MOUSE.CLICK - Event, but i need it immediately after adding to the canvas.


      Could somebody give me an advice to solve this problem?


        • 1. Re: Image width on adding
          Peter deHaan Level 4

          If you're loading the image dynamically, you may need to wait until the complete event handler before you can access the image's dimensions.



          • 2. Re: Image width on adding
            real_ideveloper Level 1

            Hi Peter.


            Thank you for your fast answer.


            When I wait until the creation is complete and afterwards i am trying to get the width parameters with EVENT.COMPLETE handler then i get the same value of 0.


            Or do i something wrong?


            Could somebody post me an example???

            • 3. Re: Image width on adding
              Vikash.kumar29 Level 3



              Use following code, may be this is what you are looking for:


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                          private function onImageLoadHandler(event:Event):void
                              var bmp:Bitmap = event.target.content as Bitmap;
                              trace("Height :: " + bmp.height);
                              trace("Width  :: " + bmp.width)
                  <mx:Image source="image.png" complete="onImageLoadHandler(event)">




              • 4. Re: Image width on adding
                real_ideveloper Level 1

                Vikash, it was the solution.



                Thank you!!!!!!!!





                After I have read your codesnippet, I've found that the event.targent.contentWidth does the same