Goal to take you to new level

Subscribe to Goal to take you to new level 24 posts, 5 voices

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

I just need to know how to make this. I’m making a game, I can do EVERYTHING but this, I want to make a leaf takes you to a new frame, when your character that is controlled by the arrow keys walks over it.

 
avatar for BigCheese BigCheese 367 posts
Try this:
if(leaf_mc.hitTest(char._x,char._y,true){
     gotoAndPlay("new_frame");
}

That will test the x,y point of your character(char) against the leaf_mc movieclip.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

Wow! Thank you so much! Your so awesome! But I got an error: Error Scene=Scene 1, layer=Layer 1, frame=1:Line 1: ‘)’ expected if(leaf_mc.hitTest(char._x,char._y,true){

Total ActionScript Errors: 1 Reported Errors: 1

 
avatar for BigCheese BigCheese 367 posts

Sorry, I missed an ending parenthesis.

if(leaf_mc.hitTest(char._x,char._y,true)){
 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

Hmm, when I try to press CNTL+ENTER, i get this:

Error Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Mouse event expected on () {gotoAndStop(10);

Total ActionScript Errors: 1 Reported Errors: 1

 
avatar for BigCheese BigCheese 367 posts

Can you post your full code? Or at least the code involving this part.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

Ok, here is the leaf:

onClipEvent (enterFrame) {

if(leaf_mc.hitTest(char._x,char._y,true)){

gotoAndPlay(10);

}

}

and here is how i move: //Move with your arrow keys, optimized at 30 FPS

onClipEvent (enterFrame) {

if (Key.isDown(Key.RIGHT)) {

this._x += 5;

}

if (Key.isDown(Key.LEFT)) {

this._x -= 5;

}

if (Key.isDown(Key.UP)) {

this._y -= 5;

}

if (Key.isDown(Key.DOWN)) {

this._y += 5;

}

}

 
avatar for BigCheese BigCheese 367 posts

You need to change gotAndPlay(10); to _root.gotoAndPlay(10); the _root. tells it to go to the tenth frame on the Main timeline.

If the first part of the code is on the leaf movie clip, you have to replace “leaf_mc” with “this”. Also make sure that “char” is replaced by the instance name of your character movieclip.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

What? it gave me the same error, I did what you said…

 
avatar for BigCheese BigCheese 367 posts

It’s kind of hard to find the problem, since I don’t have your flash file.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

Here it is: http://mihd.net/kyg8tzb

I use MX 2004 PRO

 
avatar for BigCheese BigCheese 367 posts

Dang, sorry. I’ve got Mx 2004, but not Pro.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

It’s ok, could you point me in the direction of a good tut?

 
avatar for BigCheese BigCheese 367 posts

Hmmm… I’m not sure if there is anything specific to this, but you might try googling “point hitTest flash” or something like that. You might also try googling the error message you get.

 
avatar for TheC TheC 370 posts

YourTimeHasCome-in 90 years XD

 
avatar for Lysis Lysis 320 posts

Error Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Mouse event expected on () {gotoAndStop(10);

The error is not in this section of code because you don’t have a gotoAndStop in there at all.

What code do you have at the start of frame 1? (Look where the error is reporting the problem.)

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

The code I have in frame one is “stop();” And also, it gives me that error when I test the flash document, not when pressing check.

 
avatar for Solsund Solsund 146 posts

The issue is your button “Lets go get Lady Buggin’”.

You have
on () {gotoAndStop(10);

The on handler requires a mouseEvent object to be in the parenthesis.

This can be one of a bunch of things but what you want here is likely “press”, which is when the button is clicked.

As per your hitTest handler, it’s not working because char as of itself isn’t in the scope of that movieclip.

if(this.hitTest(_root.char._x, _root.char._y,true)){
     _root.gotoAndPlay(10);
}

By adding _root to those two variables we gain a link to the char movieclip, which was created in _root.

The only problem with doing the test that way is it doesn’t fire at all when the right or bottom sides of your ladybug touch the leaf, only when the top-left corner does.

It just so happens that hitTest has another version that takes an object itself, and determines hitTesting based on the non-visible rectangle that is the bounds of the movie clip. So it becomes this, and now it will fire when the right or bottom side touches the leaf.

if(this.hitTest(_root.char)){
     _root.gotoAndPlay(10);
}

Btw, I think the name of the game is cute, I’m very interested in seeing where you take it.

Hope this helped.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

Is lost So what you’re saying is take out the root. and add handlers to the button S: | I don’t know the handlers, man, this all would’ve worked in MX 2004, PRO is really annoying, I’m the farthest things from pro. ..

 
avatar for BigCheese BigCheese 367 posts

When he says you need a mouseEvent, he means you need one of the following inside the parenthesis: release, press, rollOver, dragOver. There are some other too, but those are the basics.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

Oh, ok, thanks, I’ll test that out!

EDIT: Ok, now the leaf doesn’t work at all, I don’t even know if it worked anyway, do I need to put something were the x, and y are? If so, what?

 
avatar for Lysis Lysis 320 posts

which x and y?

did you update the code with Solsund’s third suggestion?

Anyway, without being able to look at all your code – it seems to me that if you’ve clicked the lady buggin button he mentions, you’ll already be on frame 10. You’re telling it to play from the frame it’s already stopped on. I dunno what happens for that, but I do know that if you try gotoAndStopping the frame you’re already stopped on, the frames code doesn’t get re-executed.

So – should your leaf’s hittest code be _root.gotoAndPlay(11) or something like that?

 
avatar for Solsund Solsund 146 posts

No, he’s got two ways to get to frame 10, one by pressing the button, two by moving the lady bug object over the leaf. Both ways are found on frame 1.

As per the hitTest let me explain it a bit different.

if(this.hitTest(char._x, char._y,true)){
     _root.gotoAndPlay(10);
}

When I checked it your code looked like this. The two coordinates you are passing, char._x and char._y have no scope on them so Flash pretends they have a this on the front of them. However “this.char._x” doesn’t exist so the function silently fails.

The char object is found as a child of _root, so to make sure Flash knows where to reach it you’d use _root.char._x instead.

 
avatar for YourTimeHasCome YourTimeHasCome 26 posts

THANK YOU SO MUCH ! Adding _root. worked, thanks, now I cant finally get on with my game! I hope you all like it, even though the name seems a bit funny!