Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3271970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:46:47+00:00 2026-05-17T18:46:47+00:00

Last Edit: Resolved! Well, i was unable to find the ENTIRE answer here but

  • 0

Last Edit: Resolved!

Well, i was unable to find the ENTIRE answer here but i finally got what i was after. thanks very much for all of your help and patience.

as a side note: i think i may have been having problems with using the int and Number types, upon closer inspection of my solution, i realised that Number was being used and not int. turns out number contains floating points and int doesn’t. my numbers were probably rounding whenever i tried to fix this my self. for all i know, TDI’s answer might have been spot on and the use of int for the padding might have accumulated rounded numbers.. Oh well, you learn something every day..

the correct code to constrain movie clips to a container movie clip (or sprite or whatever) in the fashion i was looking for is this:

var picContainer:PicContainer = new PicContainer();
picContainer.x = stage.stageWidth / 2 - picContainer.width / 2;
picContainer.y = stage.stageHeight / 2 - picContainer.height / 2;
addChild(picContainer);

var totalPics:int = 17;

var pic:Pic = new Pic(); //make an instance just to get its width

var xRange:Number = picContainer.width - pic.width;
var spacing:Number = xRange / (totalPics - 1);

//A little optimization: only need to calculate this number ONCE:
var yLoc:Number = picContainer.height / 2 - pic.height / 2;

for(var i:int = 0; i < totalPics; i++) {
    pic = new Pic();
    pic.x = i * spacing;
    pic.y = yLoc;
    picContainer.addChild(pic);
}

the logic is pretty simple, and i don’t know why i couldn’t get it my self, because i drew diagrams that say exactly this logic. however, i must not have put the numbers in the right places or i wouldn’t have had to ask, would i ;P

BONUS CONTENT!
as an added bonus (if anyone finds this thread looking for answers..)
you could also have the ‘pic’s fan out from the center point (but they’d still be in order of left to right) by using this code:

var picContainer:PicContainer = new PicContainer();
picContainer.x = stage.stageWidth / 2 - picContainer.width / 2;
picContainer.y = stage.stageHeight / 2 - picContainer.height / 2;
addChild(picContainer);

var totalPics:int = 5;

var pic:Pic = new Pic(); //make an instance just to get its width

var padding:Number = (picContainer.width - (pic.width * totalPics))  / (totalPics + 1);

for(var i:int = 0; i < totalPics; i++) {
    pic = new Pic();
    pic.x = padding + i * (pic.width + padding);
    pic.y = picContainer.height / 2 - pic.height / 2;
    picContainer.addChild(pic);
}

Try it out, these make for great thumbnail dock engines!

First Edit: Well, there is some progress thanks to TDI but not a complete solution.

you see, the problem remains that the movie clips do not squash completely into the container, the last one or two are left sticking out.

example:

alt text

my revised code looks like this:

var newPicContainer:picContainer = new picContainer();
var newPic:pic;

var picwidth:int = 100;
var amountofpics:int = 22;
var i:int;

//add a container
addChild(newPicContainer);

//center our container
newPicContainer.x = (stage.stageWidth/2)- (newPicContainer.width/2);
newPicContainer.y = (stage.stageHeight/2)- (newPicContainer.height/2);

var totalpicwidth:int = picwidth*amountofpics;

var totalpadding:int = newPicContainer.width - totalpicwidth;

var paddingbetween:int = (totalpadding / amountofpics);

for (i = 0; i < amountofpics; ++i)
{
    //make a new mc called newPic(and i's value)  eg. newPic1
    this['newPic' + i] = new pic();
    this['newPic' + i].width = picwidth;

    //add our pic to the container
    newPicContainer.addChild(this['newPic' + i]);

    //set the new pics X
    if (i != 0)
    {
        // if i is not 0, set newpic(i)s x to the previous pic plus the previous pics width and add our dynamic padding 
        this['newPic' + i].x = this['newPic' + (i-1)].x + picwidth + paddingbetween;
    }
    else
    {
        this['newPic' + i].x = 0;
    }
}

thanks again to anyone in advance!

Original Post:

Hello, First time posting here. I hope I’m not getting anything wrong . my problem is as follows:

I’ve got a pretty basic for loop that creates a ‘thumbnail’ and puts it next to the previous one (With a little padding) inside a containing movie clip.

var newPicContainer:picContainer = new picContainer();
var newPic:pic;
var amount:int = 9;
var i:int;

//Add our container
addChild(newPicContainer);

//center our container
newPicContainer.x = (stage.stageWidth/2)- (newPicContainer.width/2);
newPicContainer.y = (stage.stageHeight/2)- (newPicContainer.height/2);


for (i = 0; i < amount; ++i)
{
 newPic = new pic();
 newPicContainer.addChild(newPic);

    //just so i know it's adding them..
    trace(newPic.thisOne);
 newPic.thisOne = i;

    // set this one to its self (+5 for padding..) Times, the amount already placed. 
 newPic.x = (newPic.width+5) *i;
}

I’m wondering if there is some equation or ‘magic math’ that I can use to figure out what the length of the container is and have the ‘thumbnails’ be added relative to that number. basically squashing the thumbnails against each other to make them all fit inside..

something along the lines of:

newPic.x = (newPic.width *i) - stuff here to make it know not to go past the containing width;

I must admit i’m not too great with math and so this part of coding escapes me..

thanks to any takers in advance..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:46:47+00:00Added an answer on May 17, 2026 at 6:46 pm

    you can get the length of your container by either calling its width property explicitly:

    //Container Width    
    newPicContainer.width;
    

    or the newContainer is also the parent of the added pics:

    //Container Width    
    newPic.parent.width;
    

    then you need to get the total length occupied by you pics:

    var arrayOfPics:array = [pic1, pic2, pic3, pic4, pic5];
    var picsWidth:Number;
    
    for each (var element:pic in arrayOfPics)
             picsWidth =+ element.width;
    

    after than you can subtract the length of the total pics from the container to know your available padding for separation:

    var totalPadding:Number = newPicContainer.width - picsWidth;
    

    now you can determine how much padding you can afford between the pics and both sides of the container by dividing the totalPadding by the number of pics, and add an extra padding for the end.

    var padding:Number = totalPadding / arrayOfPics.length + 1;
    

    now you can simply add your pics by including the padding

    for (var i:int = 0; i < arrayOfPics.length; i++)
        {
        newPicContainer.addChild(arrayOfPics[i]);
        (i == 0) ? arrayOfPics[i].x = padding : arrayOfPics[i].x = arrayOfPics[i - 1].x + arrayOfPics[i - 1].width + padding;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to edit the navigation bar but the last li is a little
I'm using ctrl + q very often to get to the last edit location.
I am working with an edit user view that includes First name, Last Name,
Last night I got completely hosed by a worm from Dilbert.com (so be careful
I tried to install yasnippet using the normal install protocol given here . After
I want emacs to add last edit location to the mark ring, so I
IN THE END OF THE QUESTION MY LAST EDIT Hi all, I have to
Last week I created an e-shop with opencart. Now I'm trying to customize the
Last night I tried to put together something that I have had working since
Last night before going to bed, I browsed through the Scalar Data section of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.