Strange

Hi , I’m with this really weird problem and I don’t see any bugs in my code. I have this:

onClipEvent (enterFrame) {
if (_root.Kogel, hitTest(_root.Boot)) {
_root.score = _root.score +1 ;
_root.bullets = _root.bullets -1 ;
if ( _root.bullets <= 0 );
gotoAndPlay( “kogelsop” );

}

}

“Kogelsop” is a frame wich displays “out of bullets”
Now instead of going to there when _root.bullets is 0 , it goes back to 1 bullet if you hit the boat!

You’ve got some errors in your AS.

[AS]
onClipEvent (enterFrame) {
if (_root.Kogel.hitTest(_root.Boot)) {
_root.score += 1 ;
_root.bullets -= 1 ;
if ( _root.bullets <= 0 ){
gotoAndPlay(“kogelsop”);
}
}
}
[/AS]

:wink: And oh, if you read this, stay on this post, I have to say something quite long :stuck_out_tongue:

Here it goes:
onClipEvent(enterFrame) is basically all the time. You have the action gotoAndPlay(“kogelsop”); inside it. What will happen ? It will keep going to kogelsop and thus won’t advance any further.

To solve this:

  1. Create a new empty movieclip on a new layer on the timeline of kogelsop. Give it any name. Do not place it on stage yet.
  2. Create a keyframe on the frame right before the frame kogelsop.
  3. Click anywhere on the timeline between the beginning an the keyframe just created. Drag the new MC from the library (F11) to anywhere on the stage.
  4. Cut (CTRL+X)

if (_root.bullets <= 0);
gotoAndPlay(“kogelsop”);
}

from the other script and paste it to the actions window of your new movieclip. Now add onClipEvent(enterFrame){ before it and a } after it, so that it becomes

[AS]
onClipEvent(enterFrame){
if (_root.bullets <= 0){
gotoAndPlay( “kogelsop”);
}
}
[/AS]

and the other code will then be

[AS]
onClipEvent (enterFrame) {
if (_root.Kogel.hitTest(_root.Boot)) {
_root.score += 1 ;
_root.bullets -= 1 ;
}
}
[/AS]

Why does this solve the problem ? Because when the code on the new movieclip gives the command to gotoAndPlay, it will play but on the frame from kogelsop on, the movieclip is not anymore on the stage, thus also not anymore giving the gotoAndPlay command.

you still might want to lose the “;” after the if statement or it serves no purpose and the goto will run for every hittest :wink:

? It doesnt work at my PC. I still have the same prob.
Can you post an example .fla?

Anyone???

PS i’m quite new , how do you make an empty MC? Maybe it’s that why it didn’t work.

Modify > Insert New Symbol

Doesnt work what is wrong please help!

to make an empty mc go to insert and make a new movie clip ! than without doing anything return to your stage . go to library drag your mc on the stage. You will see a hollow small white dot . Place it wherever u want.
REMEMBER TO GIVE IT AN INSTANCE AND ITS INSTANCE WILL BE USED IN THE ACTIONSCRIPT !