Hi, this problem was raised in 2002 and sort of solved by Jon Bradley (code
below) but not quite the way I need.
What I¹m after is a function that divides a defined area into n equal parts
and places a clip in each part to achieve even distribution throughout the
area. Jon Bradley¹s solution below does this for only the x, y or diagonally
across both not throughout the whole area...
The math involved is beyond me I¹m afraid. Any ideas? Any help much
appreciated. Thanks!
Jon Bradley¹s original code from 2002...
// Array-based distrubtion of duplicated clips
// Can be easily modified to distribute already existing
// clips on the stage.
//
// Parameters are:
//
// clip = name of clip to duplicate <string type>
// cntrX = center point of distribution in X
// cntrY = center point of distribution in Y
// width = width of distribution
// height = height of distribution
// clipNum = total number of clips to distribute
// xFlag = distribute in X or not <boolean type>
// yFlag = distribute in Y or not <boolean type>
// dupFlag = duplicate or not?
//
// Jon Bradley, Feb 1, 2002
//
function distribute (clip, cntrX, cntrY, width, height, clipNum, xFlag,
yFlag, dupFlag) {
clipWidth = this[clip]._width;
clipHeight = this[clip]._height;
position = [[],[]];
// Populate X array with distribution values
if (xFlag) {
spacingX = clipWidth+(width-clipNum*clipWidth)/(clipNum-1);
for (var i = 0; i<clipNum; ++i) {
position[0][i] = (cntrX - .5*width) + .5*clipWidth+i*spacingX;
}
} else {
for (var i = 0; i<clipNum; ++i) {
position[0][i] = cntrX;
}
}
// Populate Y array with distribution values
if (yFlag) {
spacingY = clipHeight+(height-clipNum*clipHeight)/(clipNum-1);
for (var i = 0; i<clipNum; ++i) {
position[1][i] = (cntrY - .5*height) + .5*clipHeight+i*spacingY;
}
} else {
for (var i = 0; i<clipNum; ++i) {
position[1][i] = cntrY;
}
}
// do we duplicate or do we just position already created clips based
// on the initial clip name and an iterated value, 0 based.
for (var i = 0; i<clipNum; ++i) {
if (dupFlag) {
this[clip].duplicateMovieClip(i,i);
this[clip]._x = position[0][i];
this[clip]._y = position[1][i];
} else {
this[clip + i]._x = position[0][i];
this[clip + i]._y = position[1][i];
}
}
}
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com