Skip to Content »

FlashApe » Realigning images

 Realigning images

  • October 4th, 2004
  • 5:09 pm

There’s probably a better way to do this, but I thought it was decent so here it is. I do A LOT of work with loading a series of variable-sized images into a blank “canvas” clip at one time. So i go through the motions of creating a loop and creating the movie clips that will load the images. Now since the images are all going to be variable width or height, I can’t just set the positions of the loading clips, becasue the images might overlap. After checking to make sure that all of the images are properly loaded, I call this function:

bc[as]. private function realignImages (clip:MovieClip, axis:String, gap:Number, startPos:Number){
trace(”realigning images”);
var next = startPos;

var getArea;

(axis == “_y”) ? getArea = “_height” : getArea = “_width”;

for (var prop in clip){
if (typeof clip[prop] == “movieclip”){
clip[prop][axis] = next;
next += clip[prop][getArea] + gap;
}
}

}

and I use it like so:

bc[as]. realignImages(bannerCanvas, “_x”, yGap, numBanners, 0);

You just pass in the clip holding the images, the axis you want to align the clips on, the spacing between the images, and the starting position the first img. The “numBanners” and “yGap” in the sample above were just variables i had set earlier. Obviously this will align all movieclips inside the clip that you pass to the function, so be carefull if you’re creating other clips int here as well.

Pretty small time I know but maybe someone out there can use it.

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>