A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Detecting image width/height loaded by XML

  1. #1
    Member
    Join Date
    Sep 2005
    Posts
    45

    Detecting image width/height loaded by XML

    I am able to load images into my file by designating their locations in an XML file using AS3. I'd like to be able to determine the width and height of the individual images without having to manually enter each one into the XML file.

    I think once I reach this point, I'll be able to figure it out on my own:
    I want to be able to load an image to the stage and trace its width.

    Is there a simple way to do this?

    Thanks.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Once you have the image loaded, the Loader width and height will be the image width and height. You cannot determine the width and height before you load it.

  3. #3
    Member
    Join Date
    Sep 2005
    Posts
    45
    Thanks, but it doesn't seem to be working in practice. I probably left something out.

    PHP Code:
    function loadPics(xThumb:XMLList):void{
        
    imageLoader = new Loader();
                    
        
    imageLoader.load(new URLRequest(xThumb[1]));
        
    imageLoader.1;
        
    imageLoader.1;
        
    //s is an empty movie clip on stage
        
    s.addChild(imageLoader);

    //this just traces out 0, but the picture is several hundred pixels wide
        
    trace(imageLoader.width);
        


  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    At the time you are tracing, the picture is still loading. You need to put in a listener for Event.COMPLETE, and do your size dependent stuff in there.

  5. #5
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    I just made something similar and can't get images width nor height, I used the events, my progress bar works without problems but when Event.COMPLETE happens I trace the width and heigth and are both 0.
    And if I try to change height or width after finish loading, the picture disappears. I just can change size with scaleX or scaleY but I need to fix it to a pixel number and each image is different. Please help.

    Thanks.

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Damn!!!! it was very simple. Don't use Event.COMPLETE, use Event.INIT, with this one all vars are ready to use.

  7. #7
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    no it's wrong, Event.COMPLETE is OK, I just made a mistake and was accessing another object. but you must use:


    loaderName.contentLoaderInfo.addEventListener(Even t.COMPLETE,yourHandler);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center