[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

setting attach movie params inside a loop

Posted on 2003-11-12
5
Medium Priority
?
299 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

872 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