Link to home
Start Free TrialLog in
Avatar of nickaxl
nickaxl

asked on

setting attach movie params inside a loop


can someone tell me what's wrong with this?? here's my AS :

d = 100;
for (j=0; j<3; j++) {
// some things happen in here, not important
for (i=0; i<3; i++) {
_root.attachMovie("cc_trigger", "card_trigger"+i, d, {_xgX+j*spread, _ygY-(cardSize*i), textbox:cardText[i], Id:j});
d++;
trace (j);
}
}

I've got two loops which attach clips to the stage in a 3 x 3 matrix.

the problem is "Id:j" in the second "for" loop. it's should set the variable "Id" in the 3 clips in the first row to "0", the 3 clips in the second row to "1" and the 3 in the third row to "2".

Instead it sets all the Id's in all clips to 2 (??) (ie it seems to be waiting til all the loops are finished and then looking at what "j" ends up as, which is 2).

You'll see in the output window when you trace "j" it goes
0
0
0
1
1
1
2
2
2

which is what it should do!! help?

Nick Fracture
 
Avatar of negatyve
negatyve

the correct sintax is:

// "card_trigger" + d
_root.attachMovie("cc_trigger", "card_trigger" + d, d

and not

// "card_trigger" + i
_root.attachMovie("cc_trigger", "card_trigger" + i, d
Avatar of nickaxl

ASKER

no, that's not it. Sorry, the code was incomplete, so i'll post it all so it's (hopefully) less confusing. The problem is that the "j" variable which gets set in the first "for" loop passes at runtime like it should to all the variables i'm using it to set EXCEPT the one called "Id".

Alternatively, the .fla is at http://www.fracture.co.nz/forums.fla if you want to have a look.

Here's all the AS that's on the first frame of my mc:

//
// set misc variables
//
d = 200;
t = 0;
spread = 214;
menuSpeed = 5;
textSpeed = 5;
ogX = 7;
ogY = 147;
maskSize = 200;
cardSize = 70;
marginT = 7;
marginB = 67;
//
// set text variables
//
cardText = new Array();
cardText[0] = "yeah number one yo.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[1] = "yeah number two.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[2] = "yeah number three bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[3] = "yeah number four bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[4] = "yeah number five bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[5] = "yeah number six bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[6] = "yeah number seven bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[7] = "yeah number eight bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
cardText[8] = "yeah number nine bro.\rhere's some test text.\r3 lines.\rmaybe 4.\rfive.\rsix.";
//
// create mask clips
//
function cc() {
      active = false;
      newY = this._y;
      newH = this._height;
}
cc.prototype = new MovieClip();
cc.prototype.onEnterFrame = function() {
      this.read = this.difY;
      this.read2 = this.difH;
      if (this.active) {
            this.difY = this.newY-this._y;
            this._y += this.difY/menuSpeed;
            this.difH = this.newH-this._height;
            this._height += this.difH/menuSpeed;
            if (Math.abs(this.difY)<0.2 && Math.abs(this.difH)<0.2) {
                  this._y = this.newY;
                  this._height = this.newH;
                  this.active = false;
            }
      }
};
Object.registerClass("cc", cc);
//
// make the matrix
//
for (j=0; j<3; j++) {
      _root.attachMovie("cc_cardholder", "maskedT"+j, d, {_x:ogX+j*spread, _y:0});
      d++;
      _root.attachMovie("cc_cardholder", "maskedB"+j, d, {_x:ogX+j*spread, _y:0});
      d++;
      _root.attachMovie("cc_textholder", "maskedC"+j, d, {_x:14, _y:7});
      d++;
      _root.attachMovie("cc", "maskT"+j, d, {_x:ogX+j*spread, _y:-46});
      d++;
      _root.attachMovie("cc", "maskB"+j, d, {_x:ogX+j*spread, _y:214});
      d++;
      _root.attachMovie("cc", "maskC"+j, d, {_x:ogX+j*spread, _y:154, _height:marginB-marginT});
      d++;
      _root["maskedT"+j].setMask(_root["maskT"+j]);
      _root["maskedB"+j].setMask(_root["maskB"+j]);
      _root["maskedC"+j].setMask(_root["maskC"+j]);
      for (i=0; i<3; i++) {
            _root["maskedT"+j].attachMovie("cc_card", "card"+i, d, {_x:7, _y:ogY-(cardSize*i), textbox:cardText[t]});
            d++;
            _root["maskedB"+j].attachMovie("cc_card", "card"+i, d, {_x:7, _y:ogY-(cardSize*i), textbox:cardText[t]});
            d++;
            _root.attachMovie("cc_trigger", "card_trigger"+i, d, {_x:ogX+j*spread, _y:ogY-(cardSize*i), textbox:cardText[t], Id:j});
            d++;
            t++;
      }
}
//
stop();
ASKER CERTIFIED SOLUTION
Avatar of negatyve
negatyve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nickaxl

ASKER

thanks so much, yeah that worked. I get it now. I used my "t" variable to name them instead of "d", gives them individual names in order. nice one!
you're welcome! :)