PDA

View Full Version : Extreme Newbie Alert!


Nochte
10-18-2002, 06:06 PM
Please go easy on me... Very new to Actionscripting.
I am just trying to make 10 box bounce around.
I made one box bounce, and then went back to try to modify the script to add 9 more. and have done something obviously wrong. please advise. mold me. teach me.

Array(xdir,ydir,speed);
for(a=1;a<10;a++) {
duplicateMovieClip (_root.box, "box"+a, a);
xdir[a]=Math.random()*5;
ydir[a]=Math.random()*5;
speed[a]=3;
setProperty ("box"+a, _x, Math.random()*300);
setProperty ("box"+a, _y, Math.random()*300);
}

onEnterFrame = function() {
for(a=1;a<10;a++);
if("box"+a._x>300 or "box"+a._x<0) {
xdir[a]=xdir[a]*-1;
}
if("box"+a._y>300 or "box"+a._y<0) {
ydir[a]=ydir[a]*-1;
}
"box"+a._x+=(speed[a]*xdir[a]);
"box"+a._y+=(speed[a]*ydir[a]);
"box"+a._rotation+=5
};

Once you stop laughing, feel free to throw some advice my way.
Nochte.

jimburton
10-18-2002, 06:40 PM
it's actionscript Jim, but not as we know it...

:) right concepts but try:


for(var a=1;a<10;a++) {
duplicateMovieClip (_root.box, "box"+a, a);
_root["box"+a].xdir = Math.random()*5;
_root["box"+a].ydir = Math.random()*5;
_root["box"+a].speed = 3;
_root["box"+a]._x = Math.random()*300;
_root["box"+a]._y = Math.random()*300;
}

onEnterFrame = function() {
for(var a=1;a<10;a++){
with(_root["box"+a]) {
if(_x>300 || _x<0) {
xdir *= -1;
}
if(_y>300 || _y<0) {
ydir *= -1;
}
_x+=speed*xdir;
_y+=speed*ydir;
_rotation+=5
}
}
};


let me know if you're not sure about the how and why that code works...it does what you were trying to do, but with the right syntax,

hope this helps,

Nochte
10-18-2002, 07:53 PM
yeah. its fairly obvious I havent coded since Basic almost.
I was pretty close with stuff... I was unaware of the For-With combo... and putting [ ] around the duplicate names... I really appreciate the help.
So much to learn, so little time while at work.

Nochte

Nochte
10-18-2002, 08:36 PM
yeah. its fairly obvious I havent coded since Basic almost.
I was pretty close with stuff... I was unaware of the For-With combo... and putting [ ] around the duplicate names... I really appreciate the help.
So much to learn, so little time while at work.

Nochte

jimburton
10-18-2002, 10:42 PM
glad to be of service :) ... there are some good tutorials on this site, which are a good way to learn new aspects of flash & as...keep it up!

tiger
10-21-2002, 04:42 AM
im new too but you lost me :)

jimburton
10-21-2002, 08:52 AM
tiger, perhaps it would make sense to start with some tutorials too? The code above is basic stuff