I am trying to read the width and height of a locally loaded image. This seems to work for images that do not exceed the sizes limited by Flash Player 10 ( http://kb2.adobe.com/cps/496/cpsid_49662.html ), but as soon as the images are larger, the width and height remain 0. Strange the thing is that from time to time I can read the dimension of these large images, but most of the time not. I understand that this may be due to a playerβs limitation, but then I would at least expect the error to be consistent.
I want to check this because there is no use uploading such a large image, since it will not be displayed in any case, but it would be useful to provide a detailed error message to the user.
Any ideas on this?
Here is the code I use to upload the image locally and read the measurement:
private function chooseImageButton_clickHandler(event:Event):void { var allowedTypes:String = "*.jpg;*.png"; m_uploadFileReference = new FileReference(); m_uploadFileReference.addEventListener(Event.SELECT, uploadFileReference_selectHandler); m_uploadFileReference.addEventListener(Event.COMPLETE, uploadFileReference_completeHandler); m_uploadFileReference.browse([new FileFilter("Image Files (" + allowedTypes + ")", allowedTypes)]); } private function uploadFileReference_selectHandler(event:Event):void { m_uploadFileReference.load(); } private function uploadFileReference_completeHandler(event:Event):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded); loader.loadBytes(m_uploadFileReference.data); } private function onImageLoaded(e:Event):void { trace(e.target.content.width); }
source share