00:00
00:00
Newgrounds Background Image Theme

CleanCosmos just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Actionscript codes here!

393,054 Views | 7,981 Replies
New Topic

Response to Actionscript codes here! 2003-08-22 14:28:04


does anyone happen to have the code for a rotating menu? if so could u please post it cuz Im having massive trouble with it... I know the obvious parts like how to make all the buttons and put actionscript to them but I cant get the rotating part down.

Response to Actionscript codes here! 2003-08-22 15:52:24


At 8/22/03 08:23 AM, Reinesanns wrote: What is the code for making gravity constant, so that a "character" (or whatever) when walking on no other object falls from it down?

Here you go: A jumping script with falling when not on a object. Hope it helps. Dont forget to label the ground 'ground'


onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) && !jumping) {
vel_y = 40;
jumping = true;
}
if (jumping == true) {
vel_y -= 2;
if (vel_y<=-15) {
vel_y = -15;
}
this._y -= vel_y;
}
if (_root.ground.hitTest(this._x, this._y+50, true)) {
vel_y = 0;
jumping = false;
}
}
onClipEvent (enterFrame) {
this._y += 16;
if (_root.ground.hitTest(this._x, this._y+50, true)) {
this._y -= 16;
}
}


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-22 16:59:09


Anyone know how to throw an object?


BBS Signature

Response to Actionscript codes here! 2003-08-22 18:18:57


At 8/22/03 02:28 PM, GlennaclawZ wrote: does anyone happen to have the code for a rotating menu? if so could u please post it cuz Im having massive trouble with it... I know the obvious parts like how to make all the buttons and put actionscript to them but I cant get the rotating part down.

do you mean to have the whole menu rotating, or parts of it rotating? either way, put this script in whatever you need to.

onClipEvent(enterFrame) {
_rotation += 5;
}

you can change number to make it rotate faster or slower

Response to Actionscript codes here! 2003-08-22 18:25:47


At 8/22/03 03:52 PM, eviLudy wrote:
At 8/22/03 08:23 AM, Reinesanns wrote:
Here you go: A jumping script with falling when not on a object. Hope it helps. Dont forget to label the ground 'ground'

that's just fargate's stolen jumping script... and it's not even what he asked for. read it over again and you'll know what he wants. my solution to his script would be...

onClipEvent(load) {
g = 1.5;
falling = 2
}
onClipEvent(enterFrame) {
if (this.hitTest(_root.ground) == false) {
fall = true;
}
if (fall == true) {
_y += falling;
falling *= g
}
}

Response to Actionscript codes here! 2003-08-22 18:29:45


At 8/22/03 04:59 PM, denacioust wrote: Anyone know how to throw an object?

that's... really vauge

Response to Actionscript codes here! 2003-08-22 18:31:48


ya i guess but ur wrong wron evil hahahaahahaha dieeeeee

Response to Actionscript codes here! 2003-08-23 11:15:33


At 8/22/03 06:31 PM, Da_Reaper46 wrote: ya i guess but ur wrong wron evil hahahaahahaha dieeeeee

Who are you talking to??


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-23 13:06:43


At 8/22/03 04:59 PM, denacioust wrote: Anyone know how to throw an object?

yes.

Response to Actionscript codes here! 2003-08-23 13:48:57


whats the code for like when you press a key your movie starts? and totally explain it please....

Response to Actionscript codes here! 2003-08-23 15:12:53


At 8/23/03 01:06 PM, Idoru wrote:
At 8/22/03 04:59 PM, denacioust wrote: Anyone know how to throw an object?
yes.

Well tahts all I needed to know


BBS Signature

Response to Actionscript codes here! 2003-08-23 15:20:07


At 8/23/03 01:48 PM, Grim8Evil wrote: whats the code for like when you press a key your movie starts? and totally explain it please....

Alright at the start in frame one give a stop; action
Now make a blank movieclip (ctrl + F8 and go back to main stage) open your library and put it on the stage give it action

onClipEvent (enterFrame) {
if (Key.isDown(Key.ENTER)) {
_root.play();
}
}

Al right well change the enter to Whatever(must be in capitals.)If you want to use letters then tell me which letter you want and I'll give you the code coz its different for letters.


BBS Signature

Response to Actionscript codes here! 2003-08-23 15:32:01


Platformer Game
To start off make a character make it an MC
And make a ground mc give it instance ground

Give your character Action:
_________________________________________________________________
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) && !jumping) {
vel_y = 40;
jumping = true;
}
if (jumping == true) {
vel_y -= 2;
if (vel_y<=-15) {
vel_y = -15;
}
this._y -= vel_y;
}
if (_root.ground.hitTest(this._x, this._y+50, true)) {
vel_y = 0;
jumping = false;
}
}
onClipEvent (enterFrame) {
this._y += 16;
if (_root.ground.hitTest(this._x, this._y+50, true)) {
this._y -= 16;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += 5;
this.play ();
} else if (Key.isDown(Key.LEFT)) {
this._x -= 5;
this.play ();
}
}


BBS Signature

Response to Actionscript codes here! 2003-08-23 15:35:43


I'm sorry i'm not posting much anymore. Im kinda, empty of helpfull scripts now. Posted almost all of them...


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-23 16:11:49


At 8/23/03 03:35 PM, eviLudy wrote: I'm sorry i'm not posting much anymore. Im kinda, empty of helpfull scripts now. Posted almost all of them...

Well keep findin more I'm learning a lot from u


BBS Signature

Response to Actionscript codes here! 2003-08-23 16:16:32


I would post some of my codes but none of them are interesting. Most of them are stupid stuff that i did just as tests. And i think the little games that i have made have all been covered in here before. so i guess i have nothing to post then :(


I could surely die

If I only had some pie

Club-a-Club Club, son

BBS Signature

Response to Actionscript codes here! 2003-08-23 16:22:40


Soon I'll make a comeback with lots of glorius scripts...


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-23 16:28:41


Well lets start repeating sripts somoen gimme a throwin script
Heres how to save the game:(requires flash 6)
Object.prototype.setCookie = function(c, n, v) {
var so = SharedObject.getLocal(c);
so.data[n] = v;
so.flush();
};
Object.prototype.getCookie = function(c, n) {
var so = SharedObject.getLocal(c);
return so.data[n];
};

Just let this code run once, and it will do the job (please don't ask me how it works, I don't know, it just works)

Now we can use two functions:
getCookie("name","itemname")
setCookie("name","itemname", var_to_save)

of course name stands for how to call the file, itemname is the subject in the file (you can have as many as you want) and when saving a variabele, it needs to know what to save.

As you can see, you save 1 variabele at a time. In a game, many variabeles influence the progress and need to be saved. I'm working on a game too and didn't want to save each variabele at a time.

This is where arrays come in handy.
Just think of an array as a database, it contains as many variabeles as you want.

You can declare an array in 3 ways, I use only one, because it give's the array's subjects ogical names.

_root.database = new Array(name, age, sex);

Now you have a database Array wich contains 3 variabeles.
You can acces these variabeles using _root.database.name.

After asigning vars to it, you can export it using

this.setCookie("database","item1",_root.database)

and reload it using:

_root.database = this.getCookie("database","item1")


BBS Signature

Response to Actionscript codes here! 2003-08-24 02:51:24


At 8/22/03 06:18 PM, ChocolateChipClock wrote:

do you mean to have the whole menu rotating, or parts of it rotating? either way, put this script in whatever you need to.

onClipEvent(enterFrame) {
_rotation += 5;
}

you can change number to make it rotate faster or slower

if I were to have it stop when the mouse is over a button would I put in the buttons actionscript...

on(mouseOver)
{
stop("instancename");
}

on each button?
or how would I do that?

Response to Actionscript codes here! 2003-08-24 03:46:32


Ok. Noone bite my head of for this , I'm still learning AS.

Can someone explain hitTest in idiot terms? I've tried a few tutes , but I still cant get to grips with it.

Response to Actionscript codes here! 2003-08-24 09:04:11


At 8/24/03 03:46 AM, rangi wrote: Ok. Noone bite my head of for this , I'm still learning AS.

Can someone explain hitTest in idiot terms? I've tried a few tutes , but I still cant get to grips with it.

It's quite easy actually.

Example:

if (_root.movieclip1.hitTest(_root.movieclip2)) {
// PUT HERE SOME ACTIONS LIKE GOTOANDPLAY
}

in The above script you can see a comment. That is the place where you put actions when a movieclip collides with another movieclip. the 1st movieclip is labelled movieclip1 and the 2nd one movieclip2


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-24 09:25:31


If your making a game like my criminality. Here's a tutorial of using buttons to:

-sleep, raise your strenght
-work, payment is strenght*5
-Sleep, Make HP back to 100
-Buy a gun for $400

1) Put these actions in the first frame of your game:

_root.str=0;
_root.cash=0;
_root.hp=100;
_root.guns=0;

2) Make a button, wich will be for resting, to get your HP back to 100, and add this script to it:

on (release) {
_root.hp=100;
}

3) Make a button, wich will be for training your strenght. This Provides 2 str a time, but takes 50 HP. This is the script for the button:

on (release) {
if (_root.hp > 49) {
_root.hp -= 50;
_root.str += 2;
}
}

4) Make another button, wich will be for the player to work. This pays your strenght times 5, but takes 20 HP. The script 4 it:

on (release) {
if (_root.hp > 19) {
_root.hp -= 20;
_root.payment=0;
_root.payment += _root.str;
_root.payment *= 5;
_root.cash += _root.payment;
}
}

5) And make a button for buying a gun, wich costs $400, here's the script.

on (release) {
if (_root.cash > 399) {
_root.guns += 1;
_root.cash -= 400;
}
}

It's almost done now... Just make 4 dynamic textboxes.

Link the 1st one to the variable str this text box contains the players strenght.

Link the 2nd one to the variable cash this text box contains the players cash.

Link the 3rd one to the variable hp this text box contains the players HP.

Link the 4th one to the variable guns this text box contains the players amount of guns.

And now ur done~!

~EviLudy


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-24 11:03:17


Evil ludy... i heard someone say one time that you had posted a tutorial to make a sidescrolling game like alien hominid... if so then could you tell me where i can find it?


- Sig provided by ME of the NGSM

- If you try to stay high, your bound to stay low. -

- If I make you a sig, please credit me here -

BBS Signature

Response to Actionscript codes here! 2003-08-24 12:28:39


Sum1 Asked for a alien hominid type of game?

1)Draw your player, the ground, some walls to jump over, and some platforms in the air. And spikes beneath the platforms.

2)Make the player a movieclip
Make all the walls a movieclip
Make all the spikes a movieclip
Make the ground and the platforms a movieclip

3)Label the movieclips like this:
The walls > Walls
The ground and platforms > Ground
The spikes > roof

4) Make the movie framerate 20 (Else the movement and stuff will be too slow)

5)And add this long script to the player movieclip:

onClipEvent (load) {
// Set the move speed
moveSpeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
if (_root.Walls.hitTest(getBounds(_root).xMax, _y, true)) {
} else {
this._x += moveSpeed;
this.gotoAndStop(3);
}
// Move Right
} else if (Key.isDown(Key.LEFT)) {
if (_root.Walls.hitTest(getBounds(_root).xMin, _y, true)) {
} else {
this._x -= moveSpeed;
this.gotoAndStop(4);
}
// Move Left
}
}
onClipEvent (load) {
grav_y = 0;
jumping = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE) && !jumping) {
vel_y = 36;
jumping = true;
}
if (jumping == true) {
vel_y -= 2;
if (vel_y<=-15) {
vel_y = -15;
}
this._y -= vel_y;
}
if (_root.ground.hitTest(this._x, this._y+27, true)) {
vel_y = 0;
jumping = false;
}
}
onClipEvent (enterFrame) {
this._y += 16;
if (_root.ground.hitTest(this._x, this._y+27, true)) {
this._y -= 16;
}
}
onClipEvent (enterFrame) {
if (_root.roof.hitTest(this._x, this._y-30, true)) {
vel_y = -16;
}
}

---SHOOTING NOT INCLUDED---


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-24 13:00:16


Thanks for that script about gravity! And there's one more thing I wonder:

In the walking script, where you you place different movie clips of "character" walking in differens direction, and when you test the movie character is walking and all, but the movieclips with him walking never stops, so even if I'm not pressing enymore he's still walking on.
But after loking a bit closer on the script, I began to wonder if it's possible to trigger an event by releasing a key instead of pressing. It would really help caus then I would just add that "go to frame" command to that script and make a frame with character just standing.

Response to Actionscript codes here! 2003-08-24 13:11:58


You could do something with the !(not) operator.

if (!Key.isDown(Key.UP) && !Key.isDown(Key.DOWN) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)){
gotoAndStop("frame where still pic is");
}

That always works.
And if you want to stop in the direction it was moving in, you could put a

if (!Key.isDown(directional key for this frame)){
gotoAndStop(frame in the same direction, not going);
}

on the every directional frame. that way, if its on that frame and the key is not down, it goes to the desired frame

If you get what I mean =)

BTW: Of course, you would have to change the "frame in the same direction, not going" and such to the certain frame. :P

Response to Actionscript codes here! 2003-08-24 13:15:26


THANKEE!!!

Response to Actionscript codes here! 2003-08-24 13:32:12


Your welcome. I'm just surprised you didn't ask any questions.

I couldn't even understand what I wrote haha

Response to Actionscript codes here! 2003-08-24 14:51:30


At 8/24/03 01:32 PM, PikaExploder wrote: I couldn't even understand what I wrote haha

Not understanding what u wrote yourself is baaad...
Are u drunk? =)


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-08-24 16:15:27


At 8/24/03 03:46 AM, rangi wrote: Ok. Noone bite my head of for this , I'm still learning AS.

Can someone explain hitTest in idiot terms? I've tried a few tutes , but I still cant get to grips with it.

hitTests detect the collosion of two movieclips.

there are two ways to do a hitTest, here's one form

movieclip.hitTest(mc)

here is that form being used.

this.hitTest(_root.movieclip);

this is the movieclip the script is currently in. _root.movieclip is the one it collides into.

then, there is this type...

movieclip.hitTest(_x, _y, shapeflag);

this.hitTest(_root.movieclip._x-50, _root.movieclip._y+100, true);

_root.movieclip._x-50 is the x position it collides with, and _root.movieclip._y+100 is the _y position it collides with. true is to specify if the shapeflag is true or false. if it's true, it recognizes the whole area of the object (this would be for a movieclip that is fully enclosed) and if it's false, then it only recognizes the parts that are actually drawn (this would be for boundaries so that it doesnt think the bounds are everywhere inside this lines. i know shapeflags are hard to explain, but with enough experimentation you should get it).

hitTests are mainly just used in if statements.

i hope that all helped a bit.