Programming error

9 posts

Flag Post

I’m trying to start a simple flash game, and I have two movie clips; a movable character and an obstacle. When the character hits the obstacle, the game’s supposed to go to frame 2 and stop (the game over screen). Instead, the game freezes up and flashes rapidly between the two frames. Anything else that I put in instead of the gotoandstop works, so I don’t think it’s how I’m doing the if statement. Anyone know how to fix this?

 
Flag Post

Can you post your game code in here? Use the (pre) (/pre) HTML tags.

 
Flag Post

Here’s the code for the obstacle:


onClipEvent (enterFrame) {
if(root.wall.hitTest(root.red)){
gotoAndStop(2);
}
}

“red” is the name of the character

 
Flag Post

Well, I don’t know. There’s not enough here for me to tell what’s going on. Try putting a stop(); command on frame two.

Other than that, you should try not to use onClipEvents because they are depreciated. Instead, write your main game code inside the onEnterFrame like this, so you can scope your code effectively:

this.onEnterFrame = function() {

}
 
Flag Post

Put a stop(); command on frame 1 also!

 
Flag Post

Ok, I put a stop(); command on frames 1 and 2, and to get rid of the onClipEvent statement I changed the code to this:


this.onEnterFrame = function(){
if(root.wall.hitTest(root.red)){
gotoAndStop(2);
}
}

But I’m getting this error:

Error Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
this.onEnterFrame = function() {

Total ActionScript Errors: 1 Reported Errors: 1

And when I move the character into the wall nothing happens. Do you know what I’m doing wrong?

 
Flag Post

you need that on the main timeline and not on the movieclip.

 
Flag Post

Yes, what Woad said ^.

You also should put delete onEnterFrame inside the if statement as well (above gotoAndStop(2) ) because the EnterFrame event will persist until you remove it or the timeline it was created on.

 
Flag Post

This may seem boring or mean, but I suggest reading up on Actionscript and Object Oriented Programming. You’re obviously struggling with the concepts of how to organize your code blocks, and even where to put your code in the first place for a Flash game.