PDA

View Full Version : Could anyone help me with this?



Greatfaith
September 4th, 2006, 06:13 PM
The main character of the game is a guy that you controll with the directional keys. You are supposed to go left and right to catch the balls that fall from the sky on your head, and you get a point. What I need help with is the balls falling script. I have a red ball, where the AS is written, and it has the instance name "ball", and I have a yellow ball, and it's instance name is "bad_ball". The bad_ball doesn't have any script in it. I want the yellow ball, to drop one random time in between 10 red ball. Please help me get the random yellow ball to work, and that there are more balls than one that can fall at the same time, because with this script, only one ball can fall, and when it disappears another one falls down.

Here's the script.


onClipEvent (load) {
speed = 5;
_x = random(Stage.width);
_y = random(Stage.height);
}

onClipEvent (enterFrame) {
_y += speed;
if (_y>=400) {
_x = random(Stage.width);
_y = random(Stage.height)- 300;
}
}

I hope you understand anyting of what I asked about, because I think it might have been a little unclear. If so, just ask, and I'll try to be more exact.

-Greatfaith-

DangerousDan
September 5th, 2006, 07:14 PM
Here's somewhat what you could do, you'd have to set the ball to export for actionscript...
Main Frame Code:
ActionScript Code:

i = 0;
j = 0;
speed = 5;
function createBall(num){
for(c=0;c <= num; c++){
i = getNextHighestDepth();
attachMovie("ball", "ball"+i,i);
_root.["ball"+i].onEnterFrame = function(){
_root.["ball"+i]._y += speed;
}
}
}
setInterval(createBall(3), 5000);





Something like that, might be some syntax issues... I'm sick and have homework so I really just rushed it, I'm sure someone can build off this...

DangerousDan
September 7th, 2006, 07:44 PM
Changed...

ball.["ball"+i]
to...

_root.["ball"+i]
I'm working on an example for you, too bad it is on my school computer which I won't see again till monday. I:-)

Joppe
September 8th, 2006, 09:20 AM
_root.["ball"+i]
Is uncorrect, if you use that code you dont have an dot between the _root and the[

_root["ball"+i]

nathan99
September 8th, 2006, 09:53 AM
ActionScript Code:

_root["ball"+i]





Yeah, he's right. When using Associative array referencing (http://www.n99creations.com/?pID=tutorials&col=Blue&tut=basics_of_actionscript_for_flash&p=27&l=Flash_MX_04) you do not use the typical dot syntax codes until after the associative array reference(unless targeting a path with it).

DangerousDan
September 8th, 2006, 07:31 PM
Yeah I'm sorry about that, my code was on my school PC so I just did it off memory... :ne: