Solved

setting attach movie params inside a loop

Posted on 2003-11-12
5
224 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
you're welcome! :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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 how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

744 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

10 Experts available now in Live!

Get 1:1 Help Now