Jump to content


Movie Clips


  • You cannot reply to this topic
8 replies to this topic

#1 whotf

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 24 March 2007 - 08:43 PM

I got a problem with movie clips. I want to play a mc("leek") inside the main movieclip...Well..And only when im holding down the UP button, when i release it, I want the movieclip("leek") to go back to the start again.

Right now "leek" just plays, and nothing changes when I hold down the UP button(or release it).

My code is:

onClipEvent (enterFrame) {
 if (Key.isDown(Key.UP)) {
	  _root.leek.gotoAndPlay(1);
 } else {
 _root.leek.gotoAndStop(1);
 }
}

Edited by whotf, 25 March 2007 - 05:11 PM.


#2 gostmn26

    Young Padawan

  • Members
  • Pip
  • 12 posts
  • Gender:Male
  • Location:14560

Posted 25 March 2007 - 01:52 PM

I am still new to AS myself but I would have to say that you need to give it a command for Key Up as well. So that it knows what to do when you release the key.

I don't see the IF..ELSE statement working because you are pressing the key and don't tell it to do something else when you release it.
onClipEvent (enterFrame)
Key.isDown(Key.UP);
{
Do Something....
}
Key.isUp(Key.UP);
{
Do something....
}
}


#3 whotf

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 25 March 2007 - 02:20 PM

View Postgostmn26, on Mar 25 2007, 04:52 PM, said:

onClipEvent (enterFrame)
Key.isDown(Key.UP);
{
Do Something....
}
Key.isUp(Key.UP);
{
Do something....
}
}

Thanks alot for trying to help me, but there is no method with the name 'isUp', and that`s why i put 'else' there.

#4 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 25 March 2007 - 04:24 PM

Maybe because you forgot to add one of these: } to the end of the script?

#5 whotf

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 25 March 2007 - 05:20 PM

View PostBen, on Mar 25 2007, 07:24 PM, said:

Maybe because you forgot to add one of these: } to the end of the script?

Sorry, I did forgot one } in the forum(now it`s edited), but not in the flash script.
I also did the syntax check, and it didn`t find anything wrong.

I will now show you the whole script to make it clear(everything else is fine).

onClipEvent (load) {
	speed = 0;
}
onClipEvent (enterFrame) {
	// go forward + make thrust visible
	if (Key.isDown(Key.UP)) {
		_root.leek.gotoAndPlay(1);
		speed += 1;
	} else {
		_root.leek.gotoAndStop(1);
	}
	// slow down after the speed of 40
	if (Math.abs(speed)>40) {
		speed *= .9;
	}
	// rotation 
	if (Key.isDown(Key.LEFT)) {
		_rotation -= 10;
	}
	if (Key.isDown(Key.RIGHT)) {
		_rotation += 10;
	}
	// math and stopping 
	speed *= .90;
	x = Math.sin(_rotation*(Math.PI/180))*speed;
	y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
	if (!_root.land.hitTest(_x+x, _y+y, true)) {
		_x += x;
		_y += y;
	} else {
		speed *= -.8;
	}
}


#6 bezz

    Young Padawan

  • Members
  • Pip
  • 23 posts
  • Gender:Male
  • Location:Berlin, NJ
  • Interests:Flash, Snowboarding, Paintball, Learning Guitar

Posted 25 March 2007 - 11:58 PM

Looks like regardless of whether or not the UP key is pressed, you are telling leek to go to frame 1. Is the thrust animation on frame 2 of leek? Maybe something like this:
if (Key.isDown(Key.UP)) {
		_root.leek.gotoAndStop(2);
		speed += 1;
}
If there is a thrust animation, make that animation its own movie clip and just insert the movie clip on frame 2 instead of having a multiframe animation directly on leek

#7 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 26 March 2007 - 01:17 AM

I found your problem. First you need to make the movieclip stop where it is (assuming this code is on your leek movieclip):
onClipEvent(load) {
		this.gotoAndStop(1);
		var isPlaying:Boolean = false;
}
Then, directly after that line:
onClipEvent(enterFrame) {
		if(Key.isDown(Key.UP)) {
				if(!isPlaying) {
						this.gotoAndPlay(2);
						isPlaying = true;
				}
		} else {
				isPlaying = false;
				this.gotoAndStop(1);
		}
}
The problem was, since the enterFrame event continuously loops, it was continuously playing from frame 1, which gave the impression that it was stopping. So I've just make a variable that is it is false, and you press the up button, it tells the clip to play, then straight after changes it to true so that it won't tell it to play again.

#8 whotf

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 26 March 2007 - 10:14 AM

View PostBen, on Mar 26 2007, 04:17 AM, said:

I found your problem. First you need to make the movieclip stop where it is (assuming this code is on your leek movieclip):
onClipEvent(load) {
		this.leek.gotoAndStop(1);
		var isPlaying:Boolean = false;
}
Then, directly after that line:
onClipEvent(enterFrame) {
		if(Key.isDown(Key.UP)) {
				if(!isPlaying) {
						this.leek.gotoAndPlay(2);
						isPlaying = true;
				}
		} else {
				isPlaying = false;
				this.leek.gotoAndStop(1);
		}
}
The problem was, since the enterFrame event continuously loops, it was continuously playing from frame 1, which gave the impression that it was stopping. So I've just make a variable that is it is false, and you press the up button, it tells the clip to play, then straight after changes it to true so that it won't tell it to play again.

Thank you, Ben! You solved it. (tho I had to change your script a bit - this.leek... etc.)
I owe you one! :biggrin: :)

#9 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 26 March 2007 - 04:43 PM

No problem :lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users