00:00
00:00
Newgrounds Background Image Theme

Coolgamer2000s 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!

390,034 Views | 7,981 Replies
New Topic

Response to Actionscript codes here! 2003-07-21 01:56:13


have you played any of the scope games where there is a small scope that you control by moving your mouse, and the scope has a small circle where you can see through it, but it is zoomed... how do you do that?

Response to Actionscript codes here! 2003-07-21 03:05:29



5) For some levels, there should be a "random encounter" so that you can fight enemies. Here's a long script for it (I s'pose it should be able to be esier, this is just a script of an old game of mine that i didn't finish...)

Lordy Ludy! I didn't really examine the script too closely, but what did stand out was the severe ass kicking you were giving to your CPU with several 26 element "switch" statements, to be executed EVERY FRAME! Switch is even slower than a string of 'else if's. Anyways, I thought i'd drop two cents in here with some code that'll save a buttload of typing and some electricity... for any event that requires a random trigger. You can use "onClipEvent(enterFrame)" *shudder* with the same code, though I'll type it up as an internal MC action (this.onEnterFrame)... cause i've got a thing for that sorta thing...


percentChance = 100/26; //1 in 26, like yer previous code

function someRandomThing() {
randomNumber = Math.random() * 100;
if (randomNumber < percentChance){
doSomeThing(); //some function that does something
}
}

this.onEnterFrame = someRandomThing;

To stack different random events, try this:


event1chance = 100/26;
event2chance = event1chance + 100/26;
event3chance = event2chanve + 100/26;
//etc...

function someRandomThing() {
randomNumber = Math.random() * 100;
if (randomNumber < event1chance){
doEvent1();
} else if (randomNumber < event2chance){
doEvent2();
} else if (randomNumber < event3chance){
doEvent3();
}
}

this.onEnterFrame = someRandomThing;

But now you wanna have, say, 26 different events of equal liklihood? That's still alot of typing... but you can always fancy about it with some loops:


numberOfEvents = 26;

event0chance = 0; // just for sake of explicitness, there is no event0

for(i=1; i<=numberOfEvents; i++){
this["event" + i + "chance"] = this["event" + (i-1) + "chance"] + (1/numberOfEvents);
}

function someRandomThing() {
randomNumber = Math.random() * 100;
for(i=1; i<=numberOfEvents; i++){
currentEventFunction = this["doEvent" + i];
if(randomNumber < this["event" + i + "chance"]){
currentEventFunction();
}
}

this.onEnterFrame = someRandomThing;

That code assumes that you've got a functon written for each event called doEvent1(), doEvent2(), etc. And I wouldn't cut n' paste this one, cuz i did't check fer typos too good. But i'm sure you get the idea.

I'll save any more brutal explanations for when i finally get around to my tutorial site :Þ

Response to Actionscript codes here! 2003-07-21 03:09:13


function someRandomThing() {
randomNumber = Math.random() * 100;
for(i=1; i<=numberOfEvents; i++){
currentEventFunction = this["doEvent" + i];
if(randomNumber < this["event" + i + "chance"]){
currentEventFunction();
}
}

Crap!! Almost forgot the most important part of this function in the 3rd example:

function someRandomThing() {
randomNumber = Math.random() * 100;
for(i=1; i<=numberOfEvents; i++){
currentEventFunction = this["doEvent" + i];
if(randomNumber < this["event" + i + "chance"]){
currentEventFunction();
break;
}
}

Response to Actionscript codes here! 2003-07-21 07:36:49


At 7/20/03 01:17 PM, Star_Cleaver wrote:
At 7/20/03 01:03 PM, eviLudy wrote: a script for lips sync!?!?
Never heard about i. Ill do my best...
dont trouble yourself. I'm pretty sure that Flash doesn't have the capabilities to read music in that way. Maybe isthatlegal is thinking of anohter program?

nope, i wasn't, its deffo flash, the thing is on

spikything.com he charges u for sum codes...and this is one of the code he charges for...so it might be a kind of extension,ornot verywell known of

Response to Actionscript codes here! 2003-07-21 07:43:28


u know in "X-Ry gogles"u can see through peoples clothes... i know mask is used,but wot scrips are needed...???

Actionscript codes here!

Response to Actionscript codes here! 2003-07-21 10:59:24


im making a maze in flash, i have the character from a top view and he can walk in all 4 directions, but i cant figure out how to make him stop when he hits the walls >:(... Any help is greatly appreciated

Response to Actionscript codes here! 2003-07-21 11:47:47


At 7/8/03 09:52 PM, AngryBinary wrote: Set up the fireball MC similar to the character MC, one frame of initializations with nothing but code in it, and four frames labeled "up", "down", "left", "right", and if applicable, some kind of "destroy" frame in the event of a hit.

Does this mean you would place a graphic or movie clip or something inside those frames with the fireball animation and destroy animation?

Response to Actionscript codes here! 2003-07-21 11:58:28


At 7/21/03 07:43 AM, isthatlegal wrote: u know in "X-Ry gogles"u can see through peoples clothes... i know mask is used,but wot scrips are needed...???

Well thats easy, you just make the most upper layer (where the mouse pointer is) a mask and the layer of the "naked" people must be masked by the most upper layer. And the layer with the clothes must be beneath the naked layer and must not be masked.


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-07-21 12:06:45


At 7/20/03 09:37 PM, Freek_Sk8er wrote: OK, since not any of my questions have been answered I'll go ahead and ask one maybe not so hard. I'm using version 5, but I think some of the MX codes might work so here it is: How can I make it so that when you jump under a platform and hit it on the bottom, then you cant pass throung it. is this a too hard question for you guys, or are you just gonna ignore me, like half the time.

I have awnsered a lot of your questions Freek Sk8er here's a jumping tutorial that will make your character unadble to go through the platforms:

COMPLETE PLATFORMER TUTORIlAL:

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;
}
}

P.S. Am I right if ur making a skate game?


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-07-21 12:11:43


At 7/21/03 10:59 AM, yourmomisamonkey wrote: im making a maze in flash, i have the character from a top view and he can walk in all 4 directions, but i cant figure out how to make him stop when he hits the walls >:(... Any help is greatly appreciated

Well how many million times have I expklained how to make walls? Here it is again:

Remove your moving script and replace it with this:

onClipEvent (load) {
// Set the move speed
moveSpeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
if (_root.Walls.hitTest(getBounds(_root).xMax, _y, true)) {
} else {
this._x += moveSpeed;
}
// Move Right
} else if (Key.isDown(Key.UP)) {
if (_root.Walls.hitTest(_x, getBounds(_root).yMin, true)) {
} else {
this._y -= moveSpeed;
}
// Move Up
} else if (Key.isDown(Key.DOWN)) {
if (_root.Walls.hitTest(_x, getBounds(_root).yMax, true)) {
} else {
this._y += moveSpeed;
}
// Move Down
} else if (Key.isDown(Key.LEFT)) {
if (_root.Walls.hitTest(getBounds(_root).xMin, _y, true)) {
} else {
this._x -= moveSpeed;
}
// Move Left
}
}

Everything that should not be able to walk trough should be in 1 movieclip labelled walls

Keep Posting

(Click my profile :D)

~EviLudy


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-07-21 12:25:38


At 7/21/03 10:59 AM, yourmomisamonkey wrote: im making a maze in flash, i have the character from a top view and he can walk in all 4 directions, but i cant figure out how to make him stop when he hits the walls >:(... Any help is greatly appreciated

i am quite new at actionscripts,but i hope this help neway...

sum@ like
onClipEvent(load){
if(this.hitTest._root.wall){
gotoAndPlay("move_none")
}
}

if it aint right, then sorry but as i sed i am new at this.

also, i did a liitle game like this,but i broke it.
ull hav to make sum variables so that wen u move left he stops facing left etc.

Response to Actionscript codes here! 2003-07-21 12:56:07


I already posted this but...

I am making a game which includes a shooting game. I made the game with 3 enemies each with their own health bar. And I made it so when all 3 are dead the game is over, you win. But right now they all shoot at the same time, since it is an animation. I would like to know how do I make them each hide behind an obstacle and pop up at random times to shoot?

I also want to know how to make it so when each dies a health powerup appears that will re-fill the health bar. I tried but when I click the health bar it doesn't do anything.

And, one more thing. I looked at the random appearance script on the first page of the topic...it was good but if I make an animation of a guy appearing, attacking, then disappearing...is there any way to make him appear in random spots but it will always play the animation. Like when I tried it was doing the looping the animation as he shot all over the place. Thanks.

Response to Actionscript codes here! 2003-07-21 15:35:05


Heres a very simple code to make a thing that displays quality make a text box Dynamic Variable quality make it a mc and give it code
onClipEvent (enterFrame) {
quality = _quality;
}


BBS Signature

Response to Actionscript codes here! 2003-07-21 16:24:37


At 7/21/03 12:56 PM, Pinhead84 wrote: I already posted this but...

I am making a game which includes a shooting game. I made the game with 3 enemies each with their own health bar. And I made it so when all 3 are dead the game is over, you win. But right now they all shoot at the same time, since it is an animation. I would like to know how do I make them each hide behind an obstacle and pop up at random times to shoot?

I also want to know how to make it so when each dies a health powerup appears that will re-fill the health bar. I tried but when I click the health bar it doesn't do anything.

And, one more thing. I looked at the random appearance script on the first page of the topic...it was good but if I make an animation of a guy appearing, attacking, then disappearing...is there any way to make him appear in random spots but it will always play the animation. Like when I tried it was doing the looping the animation as he shot all over the place. Thanks.

I didn't check to see exactly what the code was you were using for the random appearance, but the current unfortunate trend seems to be towards onClipEvent handlers... you'll find character actions become alot easier to work with as Frame Actions placed inside the MC (that way, you can use actionscript to attach multiple enemies during gameplay that already have the script loaded without needing to duplicate offscreen clips that just eat up resources, and don't lend themselves to dynamic placement since they shouldn't be moved onscreen).

Another personal preference of mine is to put everything in a function, which makes your code ultimately neater and easier to edit, not to mention the benefits of dynamic function redefinition when you really start doin' backflips with actionscript. So here goes:

Inside enemy MC, place all your function definitions on frame 1. It's convenient having them all together and being sure they're all loaded before you need to use them. Create a function for each thing you need the enemy to do, and an array containing all the X and Y values the enemy can pop up at (for random placement).


function initializeVariables(){
//for now, i'll use coords 50,75; 21,102; and 450,12
numberOfLocations = 3;
enemyLocationX = new Array(50,21,450);
enemyLocationY = new Array(75,102,12);
}

//this is pretty much all the code you need
//to move him to a random place:
function gotoRandomPlace(){
randomIndex = Math.floor(Math.random() * numberOfLocations);
//yields 0, 1, or 2 (getting 3 is near infinite improbability)

this._x = enemyLocationX[randomIndex];
this._y = enemyLocationY[randomIndex];
}

//normally, i'd use setInterval to set an interval (haha!), but that's MX exclusive.
//instead, you can set a random number of frames to wait.

function pickRandomInterval(){
randomInterval = Math.floor(Math.random() * maxWaitTime);
return randomInterval;
}

function waitForInterval(){
waitCounter++;
if (waitCounter > randomInterval){
this.onEnterFrame = null;
waitCounter = 0;
gotoAndPlay("attack");//assumes you've labeled the attack sequence "attack"
}
}

//assumes you have linked a symbol to "healthUp" identifier... (right-click
//on symbol in library panel, select "linkage...", check export for actionscript box,
//name it "healthUp" (leave "export in first frame" box checked).
//also, always use _root.layer as layer variable when attaching clips, and
//always increment it after you use it.
function createPowerUp(){
_root.layer++;
_root.attachMovie("healthUp", "healthUp" + _root.layer, _root.layer);
_root["healthUp" + _root.layer]._x = _x;
_root["healthUp" + _root.layer]._y = _y;
_root.layer++; //i double-increment layer variables for no reason. OCD.
}

Now to use all these functions properly... add these actions to the following frames:

Frame 1:

initializeVariables();
gotoAndPlay("attack");

Last frame of attack animation (when badguy is hidden again):

stop();
gotoRandomPlace();
pickRandomInterval();
this.onEnterFrame = waitForInterval;

Last frame of death sequence (when badguy is killed and you want to spawn powerup):

createPowerUp();

As always, watch out for typos, be sure to post any further problems you have with the script, or look for my AIM "angrybinary".

randall

Response to Actionscript codes here! 2003-07-21 17:06:00


For some reason there's a glitch when I use your tutorial, Ludy. Initially, the player movie clip hits the ground and stops, which is peachy. But as soon as I jump, he hits the ground, does a little jitter, and falls through. Can you explain that, or is it due to my computer. I run MX, by the way.

Response to Actionscript codes here! 2003-07-21 17:16:55


Sigh, I guess i gotta post again cause i don't read my posts until after they're up...

In the last post, add this line the the initVariables function:

maxWaitTime = 100; //100 frames

And in the pickRandomInterval function, remove this useless line for the hell of it:

return randomInterval;

ÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞ
Randall
ÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞ

Response to Actionscript codes here! 2003-07-21 18:31:37


ok, i used the tutorial by ludy for the "skate game" but the level, she is so small. how do i make a bigger level? help please!

Response to Actionscript codes here! 2003-07-22 01:35:25


Since everyone is looking at this topic, and not replying to anything else... :)
I'm making a side shooter, and there has to be a better way for the shooting algorithm:

if (Key.isDown(65)) {
gotoAndStop(3);
duplicateMovieClip(_root.s1, _root.s2, 1);
_root.s1._y = _y;
_root.s1._x = _x;
}

Is what I'm using right now. How can I get it so it creates a new instance of the shot each time you press the button?


What may man within him hide, though angel on the outward side.

BBS Signature

Response to Actionscript codes here! 2003-07-22 02:11:51


Hey, I'm new to flash actionscript and I'm making a shooter-game for a preloader to a movie. I have all the clips drawn and as far as I got was making the ship move with the mouse. What I'm trying to figure out is how to make the laser clip fire from the ship's location (which is inconsistent). I think I'll also need a new type of duplication script to replace the laser clip, too. Can anyone help me out with a script?

Response to Actionscript codes here! 2003-07-22 04:04:19


At 7/21/03 06:31 PM, negativeclock wrote: ok, i used the tutorial by ludy for the "skate game" but the level, she is so small. how do i make a bigger level? help please!

Well, just draw the extra piece to the level and add the scrolling system (earlier explained) If I knew what the instance names of your movieclips where, i could write one for you :/


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-07-22 04:51:32


At 7/22/03 01:35 AM, Lord_Aba wrote: Since everyone is looking at this topic, and not replying to anything else... :)
I'm making a side shooter, and there has to be a better way for the shooting algorithm:

if (Key.isDown(65)) {
gotoAndStop(3);
duplicateMovieClip(_root.s1, _root.s2, 1);
_root.s1._y = _y;
_root.s1._x = _x;
}

Is what I'm using right now. How can I get it so it creates a new instance of the shot each time you press the button?

That's a pretty nifty use of the word 'algorithm'... so here's what you're probably looking for:

You need to export the laser clip for use in actionscript ('register' a new class). All you gotta do is right-click on the laser clip in the library panel, select "Linkage..", check off "Export for actionscript" and "Export in first frame", and give it an identifier name, like "laser". Now, to attach a new instance of it, you'll use a function called attachMovie, which takes as parameters a clip identifier ("laser"), an instance name for the new clip, a layer on which to place the clip (which has to be different for every new attached clip, because putting a clip on a layer removes all the other clips on that layer), and optionally, a data object with which to initialize the clip (never mind that one for now).


if (Key.isDown(65)) {
gotoAndStop(3);
_root.layer++; //increment _root.layer every time you use attachMovie, BEFORE you use it
_root.attachMovie("laser", "laser" + layer, layer);
_root["laser" + layer]._x = _x;
_root["laser" + layer]._y = _y;
}

Now all the actions that you want the laser to perform have to be 'inside' the laser MC, as frame actions, because 'external' MC actions apply only to individual instances. That's why I curse flashkit and other tutorial sites every day that I see this forum riddled with onClipEvent handler code. Basically, to translate your code from clip event actions to frame actions, copy it all into the first frame of the MC, and change the function names as follows:

onClipEvent(enterFrame){

becomes

this.onEnterFrame = function(){

And likewise with the others... this.onLoad = function(){, etc.

Randall

Response to Actionscript codes here! 2003-07-22 07:30:03


thanks for them it should help me

Response to Actionscript codes here! 2003-07-22 09:01:55


since sum people only look at the newest page of this topic, I post my first post on this topic again:

I just got myself a book Flash MX actionscript ans i've learned a lot already. So i'll post some codes. You should post too!

Movie Clip Follows Mouse
_________________________________

onClipEvent(enterFrame) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}

Movement with walls
_________________________________
onClipEvent (load) {
// Set the move speed
moveSpeed = 15;
}
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.UP)) {
if (_root.Walls.hitTest(_x,getBounds(_root).yMin,true)) {
} else {
this._y -= moveSpeed;
this.gotoAndStop(2);
}
// Move Up
} else if (Key.isDown(Key.DOWN)) {
if (_root.Walls.hitTest(_x,getBounds(_root).yMax,true)) {
} else {
this._y += moveSpeed;
this.gotoAndStop(5);
}
// Move Down
} else if (Key.isDown(Key.LEFT)) {
if (_root.Walls.hitTest(getBounds(_root).xMin,_y,true)) {
} else {
this._x -= moveSpeed;
this.gotoAndStop(4);
}
// Move Left
}
}
NOTE: To activate the walls, you must make a movieclip labelled "Walls"

Dragging Script
_____________________________________

onClipEvent(mouseDown) {
if(this.hitTest(_root._xmouse, _root._ymouse)) {
this.startDrag(true);
}
}
onClipEvent(mouseUp) {
this.stopDrag();
}

If Button
_____________________________________
on (release) {
variable += 1;
variable2 -= 1;
if (variable2 < 0) {
variable2 += 1;
variable -= 1;
}
}
Make Invisible Button
_____________________________________
on (release) {
tellTarget ("_root.movieclip") {
_visible = false;
}
}

If you need a script or anything, post your question, or if you have a good script. Post it here!

~EviLudy


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-07-22 09:29:42


thanks 4 da scripting ive just made a mess bout short game lol

Response to Actionscript codes here! 2003-07-22 13:24:39


At 7/22/03 04:51 AM, AngryBinary wrote:
Randall

Thanks much. In fact, you answered two questions! Using variables when declaring constants(like in the attachMovie function) is such an easy way to program.


What may man within him hide, though angel on the outward side.

BBS Signature

Response to Actionscript codes here! 2003-07-22 14:01:47


How would one add gravity to a sidescroller game? IE: As long as there's nothing in the way thats part of "ground" you fall (_y += 5 or something.)

Response to Actionscript codes here! 2003-07-22 14:06:53


Another quick question(I'm new at actionscripting...) but is there any better way for collision detection then the hitTest? Or at least a way to specify a circle, instead of square, bounding box?
If not, I'd be able to figure it out, but I was wondering if flash automattically did this.


What may man within him hide, though angel on the outward side.

BBS Signature

Response to Actionscript codes here! 2003-07-22 14:21:31


Question:

How do you do the scope action as in the following game.

Scope Assault

Response to Actionscript codes here! 2003-07-22 14:27:23


At 7/22/03 02:06 PM, Lord_Aba wrote: Another quick question(I'm new at actionscripting...) but is there any better way for collision detection then the hitTest? Or at least a way to specify a circle, instead of square, bounding box?

nope i'm nearly positive that flash will not do that automatically for you. hitTest is the only way.


I could surely die

If I only had some pie

Club-a-Club Club, son

BBS Signature

Response to Actionscript codes here! 2003-07-22 15:23:19


At 7/22/03 02:27 PM, Star_Cleaver wrote: nope i'm nearly positive that flash will not do that automatically for you. hitTest is the only way.

There is another way then hitTest, but you have to write it like if this._x = that._x and that stuff, there is no other special funcion. HitTest is the easiest way.

(Yo star_cleaver, I added u 2 my buddy list if u don't mind. Ur a good actionscripter too, maybe we could make a game together some day)


Swing a Little more!

.. ROCK OUT!

BBS Signature