A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Image Resize after loading through XML

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Posts
    102

    Image Resize after loading through XML

    Hi - I'm trying to resize some images into a thumbnail size after loading via XML. The problem is I can't get the images to resize. I can change the positioning via the loader2, but not the width/height. The following code only loads the last image into the last thumbnail spot. Any suggestions?


    for each (var picsChildren:XML in picsList) {

    /* ------ Loading Images into Movie Images ------ */
    if (picsChildren.name() == "image") {
    var picName:XML = picsChildren;
    var loader:Loader = new Loader();
    var loader2:Loader = new Loader();

    var picMovie = this['pic' + (i)];
    var picThumbHolder = this['thumbholder' + (i)];
    var picThumb = picThumbHolder['thumb' + (i)];

    loader.load(new URLRequest(picName));
    loader2.load(new URLRequest(picName));
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, doneLoading);
    loader2.contentLoaderInfo.addEventListener(Event.C OMPLETE, resizeLoader);

    loader.y=-186;
    loader2.y=-44.5;
    picMovie.addChild(loader);


    function resizeLoader(evt:Event) {
    loader2.width = 171;
    loader2.height = 89;
    picThumb.addChild(loader2);
    }
    i++;
    }
    }

  2. #2
    Senior Member
    Join Date
    Apr 2003
    Location
    St. Louis
    Posts
    104
    Sound like your trying to resize it before the image has actually drawn into the loader. Just because it's completely loaded, doesn't mean it's ready to be resized.

    Try using Event.INIT instead on the LoaderInfo object. That is dispatched once all the properties are ready to be used.
    Ben

  3. #3
    Senior Member
    Join Date
    Jul 2004
    Posts
    102
    changing to evt.INIT doesn't make a difference, does the same thing.

    when I do a trace(picThumb); in the resizeLoader function, its gives me image4 4 times when it should be giving me image1, image2, image3, image4. It calls the function 4 times, but for some reason the movieClip name is the same each time. Should the function be placed outside the loop? Trying that doesn't bring in any images.

  4. #4
    Senior Member
    Join Date
    Apr 2003
    Location
    St. Louis
    Posts
    104
    Just glancing at this it looks like your running into scoping issues because your dynamically creating loader objects in a loop and redefining the event handler function every time the loop executes.

    First, move your function outside your loop. It's a function and every time it runs it redefines the function to point to the last loader2 object causing all 4 loader objects to try and resize the last one created.

    Once you've move that, change your resize loader to be dynamic base on the loader event calling it, instead of hard coding it to loader2 (that wont exist anyway once you move it out of the loop).

    function resizeLoader(evt:Event):void
    {
    evt.currentTarget.width = 171;
    evt.currentTarget.height = 89;
    }

    Use Event.Init, and stick your picThumb.addChild(loader2); into your loop.

    Event.INIT will resize everything before it draws to the screen, so you don't have to worry about things showing up large then resizing down.
    Last edited by StunnedGrowth; 11-12-2008 at 05:23 PM.
    Ben

  5. #5
    Senior Member
    Join Date
    Jul 2004
    Posts
    102
    makes sense, but I'm getting an error now:

    1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.displayisplayObject.

  6. #6
    Senior Member
    Join Date
    Jul 2004
    Posts
    102
    Also tried changing to bitmap - gets rid of error, but no images show up

    function resizeLoader(evt:Event):void {
    var image:Bitmap = Bitmap(evt.currentTarget.content);
    image.smoothing = true;
    image.width = 171;
    image.height = 89;
    image.y=-44.5;
    picThumb.addChild(image);
    }

  7. #7
    Senior Member
    Join Date
    Jul 2004
    Posts
    102
    so it works with:

    function resizeLoader(evt:Event):void {
    var image:Bitmap = Bitmap(evt.currentTarget.loader.content);
    image.smoothing = true;
    image.width = 171;
    image.height = 89;
    image.y=-44.5;
    picThumb.addChild(image);

    }

    if I change picThumb to the instance name thumbholder1.thumb1. the problem is I need to do it for thumb1 - thumb4

    doesn't seem to keep the var content for picThumb

  8. #8
    Member
    Join Date
    Aug 2008
    Posts
    96
    Hey,
    I'm actually working on almost the same exact thing as you, and I can't figure it out either.. but I'll let you know that I did have somebody posting on my thread saying something about using the bitmap class in conjunction with a bitmap array, so you can separate them out and store them individually using the array.push function.
    Just some food for thought, I know it's unhelpful at the moment but once you figure it out or I figure it out I assume we can help each other!
    --L

  9. #9
    Senior Member
    Join Date
    Apr 2003
    Location
    St. Louis
    Posts
    104
    Move your addChild into your loop when you create the holder, all the positioning and sizing will be taken care of during the init.

    Or you can position it during the loop I guess then add it, and just let the event handler do the resize when the image gets there.
    Ben

  10. #10
    Senior Member
    Join Date
    Apr 2003
    Location
    St. Louis
    Posts
    104
    I didn't test this, but you'll get the idea


    for each (var picsChildren:XML in picsList)
    {
    var picMovie = this['pic' + (i)];
    var picThumbHolder = this['thumbholder' + (i)];
    var picThumb = picThumbHolder['thumb' + (i)];

    var loader:Loader = new Loader();
    loader.y=-186;
    picMovie.addChild(loader);

    var loader2:Loader = new Loader();
    loader2.y=-44.5;
    picThumb.addChild(loader2);

    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, doneLoading);
    loader.load(new URLRequest(picName));

    loader2.contentLoaderInfo.addEventListener(Event.C OMPLETE, resizeLoader);
    loader2.load(new URLRequest(picName));
    }

    function resizeLoader(evt:Event):void {
    var image:Bitmap = Bitmap(evt.currentTarget.loader.content);
    image.smoothing = true;
    image.width = 171;
    image.height = 89;
    }
    Ben

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