[Flash]As2 help again

Started by: DarkCloud | Replies: 2 | Views: 261

DarkCloud

Posts: 164
Joined: Dec 2009
Rep: 10

View Profile
Dec 26, 2009 1:26 AM #528664
ok so I have this code
onClipEvent(load){
this._x = 0;
}
onClipEvent(enterFrame){
this._x += 5;
}
the ball is supposed to move 5 pixels right and stop but for some reason it just keeps on going and does not stop after 5 pixels can you guys tell me what I'm doing wrong...:Cry:
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Dec 26, 2009 1:36 AM #528667
onClipEvent(enterFrame){
this._x += 5;
}

Right, the first bolded part tells you that the script in the backets will repeat constantly while in this frame.

The second bolded part tells you what will be happening constantly in the frame, ie, moving 5 pixels constantly.

This can be solved with either a basic 'if' function of by putting the script into the onClipEvent(load) part.
DarkCloud

Posts: 164
Joined: Dec 2009
Rep: 10

View Profile
Dec 26, 2009 2:01 AM #528671
thanks scopioxxx I did what you said and put in
onClipEvent(load){
this._x = 0;
}
onClipEvent(enterFrame){
if(this._x<100){
this._x+=5;
}
}

it works =D