Phlasch MX question
- Started
- Last post
- 8 Responses
- ********
Okay, so I'm dynamically generating some MCs via a 'for' loop. (I am trying to put all the code on the first frame)
I set all of the MC._x to 0, then have each one 'animate' per its relative value pulled from an array.
I can't get it to work; what am I doing wrong? here's the code:
(toward the bottom I replaced 'i' with an actual value[4] and it works, but I need it to be 'i'...the last trace action is undefined as well...) thanks in advance.params = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280];
speed = 8;
for (i=0; i<10; i++) {
_root.attachMovie("box", "box"+i, i);
_root["box"+i]._x = 0;
_root["box"+i]._y = params[i];
_root["box"+4].onEnterFrame = function() {
_root["box"+4]._x += (400-_root["box"+4]._x)/speed;
//trace(params(4));
};
}
- ********0
any flash doods up right now?
- frankbb0
trace(params[4])
not
trace(params(4))
square brackets!!
- runDMB0
I think your problem maybe that you have an onEnterFrame loop inside a "for" loop. I'm not entirely sure why however because as you say, substituting i for 4 means one box does move. I'm normally pretty good with actionscript although I'm no full-on programmer so I can't help you much more. However, you can get all of the boxes to move quite easily by just putting the movement script in a loop in the mc itself. This would still let you control the movement of individual clips as you can extract the number added to the mc when you attach it using substring.
Hope this is some help
- __j0
params = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280];
speed = 8;
for (i=0; i<10; i++) {
_root.attachMovie("box", "box"+i, i);
_root["box"+i]._x = 0;
_root["box"+i]._y = params[i];
_root["box"+i].onEnterFrame = function() {
for (j=0; j<10; j++) {
_root["box"+j]._x += (400-_root["box"+j]._x)/speed;
}
};
}
- __j0
this is better..
params = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280];
speed = 8;
for (i=0; i<10; i++) {
_root.attachMovie("box", "box"+i, i);
_root["box"+i]._x = 0;
_root["box"+i]._y = params[i];
_root["box"+i].onEnterFrame = function() {
this._x += (400-this._x)/speed;
};
}
- ********0
doods Thanks for your help!!
Another question:
So I want to pull values from an array and place them where the '400' is(see below), how could I do this?
this._x += (params[i]-this._x)/speed;
DOESN'T WORK...root["box"+i].onEnterFrame = function() { this._x += (400-this._x)/speed;
};
- ********0
Puh-lease. Somebody....
- __j0
this will help,
params = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280];
params2 = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280];
speed = 8;
for (i=0; i<10; i++) {
_root.attachMovie("box", "box"+i, i);
_root["box"+i]._x = 0;
_root["box"+i]._y = params[i];
//set the param here !!
_root["box"+i].myParam2 = params2[i];
_root["box"+i].onEnterFrame = function() {
this._x += (this.myParam2-this._x)/speed;
};
}