-
need help on this function, it doesn't work.
hello all,
Two movie clips in the library; mc1(the container mc) and mc2. The purpose of the function is to attach 3 copies of mc2 with different (_y) inside mc1.
function attachMCs() {
//
var xx = 10;
var yy = 10;
_root.attachMovie("mc1", "mc1", _root.getNextHighestDepth());
_root["mc1"]._x = 5;
_root["mc1"]._y = 5;
for (var i = 0; i<=2; i++) {
_root.mc1.attachMovie("mc2", "mc2"+i, _root.getNextHighestDepth());
_root.mc1.eval("mc2"+i)._x = xx;
_root.mc1.eval("mc2"+i)._y = yy;
yy = yy+10;
}
//
}
-
.
Hi,
It seems that you want to keep it all inside of one function, you could do it like this
PHP Code:
function attachMCs():Void { var startX:Number = 10; var startY:Number = 10; var innerAmount:Number = 2;
var outerClip:MovieClip = _root.attachMovie("mc1","mc1",_root.getNextHighestDepth()); outerClip._x = 5; outerClip._y = 5;
for (var i:Number = 1; i <= innerAmount; i++) { var innerClip:MovieClip = outerClip.attachMovie("mc2", "mc2_" + i, i); innerClip._x = startX * i; innerClip._y = startY * i; trace(innerClip + " - x:" + innerClip._x + " - y:" + innerClip._y); } }
attachMCs();
thats one way.
Last edited by fruitbeard; 08-10-2015 at 11:43 AM.
-
Thanks,
the code works great!
Here is another way. The idea is to apply the concept of the array, as mc2 will be inside mc1, e.g. mc1[mc2]
Here is the code:
attachMCs();
function attachMCs() {
//
var xx = 0;
var yy = 0;
var spacing = 6;
_root.attachMovie("mc1", "mc1_New", _root.getNextHighestDepth());
_root["mc1_New"]._x = 30;
_root["mc1_New"]._y = 30;
//
for (var i = 0; i<=10; i++) {
var newName:String = "mc2_New"+i;
_root.mc1_New.attachMovie("mc2", newName, i);
_root.mc1_New[newName]._x = xx;
_root.mc1_New[newName]._y = yy;
//10: is the height of mc2, mc2 is a square 10*10
yy = yy+10+spacing;
}
}
Regards!
Last edited by Dr_flash; 08-12-2015 at 03:00 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|