?
Solved

setting attach movie params inside a loop

Posted on 2003-11-12
5
Medium Priority
?
283 Views
Last Modified: 2010-04-03

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
 
0
Comment
Question by:nickaxl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 9738725
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
0
 

Author Comment

by:nickaxl
ID: 9742620
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();
0
 
LVL 27

Accepted Solution

by:
negatyve earned 1200 total points
ID: 9742812
It's exactly the same thing. It doesn't work because you attach, inside this loop:

for (i=0; i<3; i++) {
         ....
         t++;
}

the same clip fot three times, as you call it for three times:

"card_trigger" + i

while "i" it's the same for three times.....

If you change this line:

_root.attachMovie("cc_trigger", "card_trigger" + i, d, {_x:ogX+j*spread, _y:ogY-(cardSize*i), textbox:cardText[t], Id:j});d++;

to this one:

_root.attachMovie("cc_trigger", "card_trigger" + d, d, {_x:ogX+j*spread, _y:ogY-(cardSize*i), textbox:cardText[t], Id:j});d++;

it works as expected...
0
 

Author Comment

by:nickaxl
ID: 9743048
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!
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9743481
you're welcome! :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question