To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 04-02-2004, 10:04 PM   #1
innoxism
Junior Member
 
Join Date: Apr 2004
Posts: 23
how to align a duplicated movie clip

i'm a beginner at scripting and i'd love some help. i have a movie clip called "box" which i want to duplicate into 30 instances arranged in a 5x6 column. how do i do these (duplicate AND arrange)? please please please help. thanks!
innoxism is offline   Reply With Quote
Old 04-02-2004, 10:58 PM   #2
DallasNYC
Senior Member
 
Join Date: Oct 2003
Posts: 1,354
Create 2 'for loops', one inside the other.
'i' for rows, 'x' for columns, 'z' will increment from 1 to 30:

code:

for (i=1;i<6;i++) {
for(x=1;x<7;x++){
z=z+1;
duplicateMovieClip (_root.box, "box"+z, z);
_root["box"+z]._x = i*50; // where 50 is the horizontal spacing you want
_root["box"+z]._y = x*50; // where 50 is the vertical spacing you want
}
}


Last edited by DallasNYC; 04-02-2004 at 11:02 PM.
DallasNYC is offline   Reply With Quote
Old 04-02-2004, 11:02 PM   #3
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Here's the method I was writing simultaneously as the above post. Essentially the same, except I'm putting some stuff in constants at the beginning, and I'm assuming the clip to duplicate is already in the correct position, and can be used to determine the grid size.

Code:
// adjust numbers to your taste
NBR_COLUMNS = 5;
NBR_ROWS = 6;
var clipToDupe = _root.myClip;

COL_WIDTH = clipToDupe._width;
ROW_HEIGHT = clipToDupe._height;
LEFT_MARGIN = clipToDupe._x;
TOP_MARGIN = clipToDupe._y;

FIRST_LAYER = 10;


var n = 1;
for (var y = 0; y < NBR_ROWS; ++y) 
{
  for (var x = 0; x < NBR_COLS; ++x) 
  {
    if (y == 0 && x == 0) {
      // first tile is already attached
      continue;
    }
    duplicateMovieClip(clipToDupe, "mc"+n, n+FIRST_LAYER);
    var mc = _root["mc"+n];
    mc._x = LEFT_MARGIN+x*COL_WIDTH;
    mc._y = TOP_MARGIN+y*ROW_HEIGHT;
  }
}
I should point out that I prefer to use attachMovie instead of duplicate clip, keeping the original clip in my library instead of on the stage.

This way, I don't have to 'skip' the first tile, as I had to above. In order for this to work, the clip in the library needs to be assigned an export name, such as 'rootClip', which I use below:

Code:
// adjust numbers to your taste
NBR_COLUMNS = 5;
NBR_ROWS = 6;
COL_WIDTH = 100;
ROW_HEIGHT = 100;
LEFT_MARGIN = 50;
TOP_MARGIN = 50;
FIRST_LAYER = 10;

var n = 1;
for (var y = 0; y < NBR_ROWS; ++y) 
{
  for (var x = 0; x < NBR_COLS; ++x) 
  {
    var mc = _root.attachMovie("rootClip", "mc"+n, n+FIRST_LAYER);
    mc._x = LEFT_MARGIN+x*COL_WIDTH;
    mc._y = TOP_MARGIN+y*ROW_HEIGHT;
  }
}
- Jim
__________________

Last edited by jbum; 04-02-2004 at 11:05 PM.
jbum is offline   Reply With Quote
Old 04-02-2004, 11:12 PM   #4
innoxism
Junior Member
 
Join Date: Apr 2004
Posts: 23
thanks for the help. now i have a variable called "x" that is a random whole number between 1 and 30. if variable x matches the number for one of the boxes, the visitor is shown a msg. i have a feeling that this can be done with an if loop but i'm not sure of the details. can anyone help?
innoxism is offline   Reply With Quote
Old 04-03-2004, 12:21 AM   #5
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
You didn't specify how you intend to assign numbers to the boxes, but yes, you can do that.

Code:
var n = 1;
for (n = 1; n <= NBR_ROWS*NBR_COLUMNS; ++n) 
{
  var mc = _root["mc"+n];
  if (x == mc.number) {
     trace("show message here");
     break;
  }
}
__________________
jbum is offline   Reply With Quote
Old 07-08-2005, 07:48 AM   #6
digisamuk
Junior Member
 
Join Date: Apr 2004
Posts: 27
any to randomise this?

this is kinda what im looking for im looking for a random appearance of each of the movieclips

any ideas?

thanks

ds
digisamuk is offline   Reply With Quote
Old 07-08-2005, 08:24 AM   #7
digisamuk
Junior Member
 
Join Date: Apr 2004
Posts: 27
am i missing something?

cant get it to work, have a circle in a mc that i want to place in a grid to it randomly forms one circle at a time but not in an ordered fashion.

the circle is set to be exported as the name circle

have change the code to chose this rather than the default rootClip

the code is on the first frame of the movie, not sure where to put it

but nothing happens

any clues?

i am using Flash MX is that helps, pref not to use 2004, am happy with MX for my use

thanks
digisamuk is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:46 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.