# I Need Help On Action Scripting

**URL:** <https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793>\
**Category:** classic bestof\
**Created:** [October 16, 2002, 6:14pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793 "2002-10-16T18:14:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![twalliewerty](https://avatars.discourse-cdn.com/v4/letter/t/aeb1de/32.png) [@twalliewerty](https://forum.kirupa.com/u/twalliewerty)\
**Post date:** [October 16, 2002, 6:14pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/1 "2002-10-16T18:14:46Z")

</div>

I AM DOING A SCHOOL PROJECT AND I CANT FIQURE OUT HOW TO MAKE MY SHIP THAT IM BUILDING MOVE THE RIGHT WAY. I HAVE IT SO WHEN I PRESS UP IT MOVES UP AND WHEN I PRESS LEFT AND RIGHT IT ROTATES IT LEFT AND RIGHT. IM TRYING TO FIGURE OUT HOW TO MAKE IT MOVE FORWARD IN THE DIRECTION THAT IT IS ROTATED IN. I BASICALLY CANT FIGURE OUT HOW TO MAKE IT MOVE ALONG A SLOPE… HELP ME OUT PLEASE…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 16, 2002, 6:19pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/2 "2002-10-16T18:19:51Z")

</div>

Show me the money, man. Something, a fla, a piece of code, a swf.

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 16, 2002, 10:33pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/3 "2002-10-16T22:33:43Z")

</div>

HERES MY FLASH GAME

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 16, 2002, 11:30pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/4 "2002-10-16T23:30:29Z")

</div>

remember trig? good stuff when you’re trying to work out slopes from rotation.

flash’s \_rotation interprets rotation as somewhere between -180 and 180 (rather than 0 - 360). that plus all the trig functions expecting radians as their arguments can make things a little tricky.

but once you’ve got your head around it, it’s not so hard.

here’s some prototypes i use to create steering movies (it should really be a class, but whatever):

```auto

function enableKeyMovement(clip){
	clip.onKeyDown = function(){
		this.onEnterFrame = this["keyAction"+Key.getCode()];
	};
	clip.onKeyUp = function(){
		this.onEnterFrame = null;
	};
	clip.spd = 5;
	clip.rspd = 15;
	clip.mov = {};
	clip.setSpeeds();
	Key.addListener(clip);
	trace(clip);
};

Math.dtr = Math.PI/180;
Math.radFromRot = function(rot){
	rot -= 90;
	return (rot < 0 ? 360 + rot : rot)*Math.dtr;
};

MovieClip.prototype.keyAction37 = function(){
	this._rotation -= this.rspd;
	this.setSpeeds();
//	trace(r);
};

MovieClip.prototype.keyAction38 = function(){
	this._x += this.mov.x;
	this._y += this.mov.y;
};

MovieClip.prototype.keyAction39 = function(){
	this._rotation += this.rspd;
	this.setSpeeds();
//	trace(r);
};

MovieClip.prototype.keyAction40 = function(){
	this._x -= this.mov.x;
	this._y -= this.mov.y;
};

MovieClip.prototype.setSpeeds = function(){
	var r = Math.radFromRot(this._rotation);
	this.mov.x = Math.cos(r)*this.spd;
	this.mov.y = Math.sin(r)*this.spd;
};

```

then to make a clip steerable:

```auto

enableKeyMovement(movieClip);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 17, 2002, 12:41am UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/5 "2002-10-17T00:41:29Z")

</div>

alright, i went ahead and made it a class. plus added the ability to go forward **and** change directions at the same time! (ooooh!!). ; )

here’s an as file containing the SteeringClip class:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 17, 2002, 8:52am UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/6 "2002-10-17T08:52:46Z")

</div>

Ouhh, that’s a keeper, Supra. [SIZE=1]usual question: [/SIZE] can someone rate this thread so that we don’t lose it?

It could be a good start for a game tutorial…

pom :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 2:09am UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/7 "2002-10-18T02:09:38Z")

</div>

cool a game tutorial… sounds fun… i’m in twalliewerty’s class and im makin a star fighter game… i sorta had a question… my other friend said that there was a command that loaded a movie clip directly from the library, instead of having to have it on the stage and duplicate it… i think addMovieClip or somthin… how does this work? if its even there, and if it is there, can you have movie clips in the library with actionscript already on them?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 9:18am UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/8 "2002-10-18T09:18:44Z")

</div>

It is attachMovie you’re looking for. Check the AS dictionary.

pom :cowboy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 10:46am UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/9 "2002-10-18T10:46:31Z")

</div>

I have the framework of an “Asteroids” game working. I’ll post the code for that ship as soon as I can decypher my own work. Give me a couple hours.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 4:11pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/10 "2002-10-18T16:11:16Z")

</div>

I JUST WANT TO THANK EVERYONE THAT HAS HELPED ME AND I HAVE FINALLY GOTTEN MY SHIP TO MOVE THE RIGHT WAY

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 5:39pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/11 "2002-10-18T17:39:26Z")

</div>

cool… I didn’t get to it, but I’m glad some of the other did. Supra and Pom are always good for a trig answer.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 20, 2002, 10:41pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/12 "2002-10-20T22:41:24Z")

</div>

twalliewerty, here is your answer. It’s all in percentages, the percentage of the rotation in the current quadrant. If you want to know more ask me, but here’s your fixed game with a nice loop  
for constant motion.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2004, 2:16pm UTC](https://forum.kirupa.com/t/i-need-help-on-action-scripting/6793/13 "2004-08-07T14:16:10Z")

</div>

> [@sbeener](#):
>
> alright, i went ahead and made it a class. plus added the ability to go forward **and** change directions at the same time! (ooooh!!). ; )
> 
> here’s an as file containing the SteeringClip class:

hey could i get a link to that SteeringClip class?
