Solved

setting attach movie params inside a loop

Posted on 2003-11-12
5
236 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
  • 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 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now