Skip to main content
Known Participant
September 8, 2011
Answered

Smoothing multiple images dynamically

  • September 8, 2011
  • 1 reply
  • 1683 views

Hi guys/gals

Im having trouble trying to smooth a dynamic amount of images into my scene

I have a loop which is trying to load a folder full of images into my scene, the images are going to be scaled to roughly 80% of their original size (they get scaled back to 100% so they need to stay at their current size) the loop will always get the right amount of images for the images in the folder so there isnt going to be any problems about it not not finding or loading pictures etc

When i have tried doing it recently I have my loop load my images, once the image has finished loading it calls a function which takes the data and adds it to a bitmap, which is then smoothed. The problem seems to be it only adds one of the images to the stage when its done, does anyone know the specific way of adding a large amount of images to the stage, do you have to add all the images to a list and then run the bitmap smoothing on each item in the list?

any help would be great

This topic has been closed for replies.
Correct answer Ned Murphy

Yea it dawned on me not long after that it wouldnt necessarily do the function once all the images have loaded, just after the last one has, I could have all huge files but my last picture could be tiny and it would happen in the wrong order

All im basically trying to do is run the toBitmap function after I know all the items in my array have been loaded, but as you pointed out that may not necessarily be once the last item in the loop is finished. Looking at your code could a similar problem not occur? that it might try to run the function before all the images are ready to be converted to a bitmap?


As I already mentioned, you should load your images using a functional loop if the order of presentation is important to you.  That is done by loading a file and assigning a listener for the load completion.  You use that load completion to trigger loading the next file, and continue in that manner until all images have been loaded.

1 reply

Ned Murphy
Legend
September 9, 2011

If you show the code that ends up displaying only one image it might be possible to help you resolve the problem.

WarDemonZAuthor
Known Participant
September 9, 2011

function loadImage():Void {

var i:Number

     for (i=0; i<10; i++) {

          var ImgLoader:Loader = new Loader

          ImgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, toBitmap);

          ImgLoader.load(new URLRequest("assets/"+[i+1]+".jpg"))

     }

}

function toBitmap(e:Event):void {

     var newBit:Bitmap

     newBit = e.target.content

     newBit.smoothing = true;

     this.addChild(newBit);

}

loadImage();

*this code may not be syntax perfect, I dont have access to the code right now but from memory and just logic this is what it was

This basically loads all my images starting from 1.jpg in my assets folder but only seems to display one item, i thought it might be just writing them over the top of each other but when i added some more code in to incremement the .x value it still only shows 1 item, and it doesnt even appear to be the last image, i think this code brought up the 7th picture out of 10

Ned Murphy
Legend
September 9, 2011

The code you show will work fine if you change "Void" (AS2) to "void" (AS3).  So if you can't get it working still, showing your actual code will be the best bet.