00:00
00:00
Newgrounds Background Image Theme

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

421,859 Views | 7,950 Replies
New Topic

Response to Actionscript codes here! 2007-10-24 13:17:37


At 5/2/03 03:02 AM, EviLudy wrote: 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!
codes

cool! I got that book aswell, but im only half way through since im working on a game as well! sweet, now i know what il be learning!


If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

Response to Actionscript codes here! 2007-11-09 02:20:46


hello my names daniel norman im 12 years old and im learning about flash but im stuck on somthing can you please tell me how to make objects move with your screen because im making a game but i dont know how to make this button move along with the player can you please help me?

Response to Actionscript codes here! 2007-11-09 02:26:43


At 8/20/07 07:30 AM, RiotFlash wrote: That checks for hitTest every 5 degrees. No lag!

MovieClip.prototype.cHit = function(o:MovieClip, r:Number) {
var b:Number = this._x - o._x;
var c:Number = this._y - o._y;

var a:Number = Math.sqrt(b * b + c * c);

if (a < r && o != this) {
return true;
break;
}
};

check that for no lag, no hitTest and no loop, +1 efficient. Written by none other than myself no stolen ^_^.

Response to Actionscript codes here! 2007-11-09 09:00:57


I have a question-

I'm trying to make my first game , basically there are different objects falling from the sky and I want the character (who's on the ground) to catch the items , but there are also bad objects falling if he catches them he loses points.I need action script for

a- the character to mover left and right along the "ground"

b- the falling objects

c- score board

d- if possible I wanted to have the character be able to open his catch bag or close it as well

Response to Actionscript codes here! 2007-11-15 15:33:53


Im making a game where a button needs to be clicked, lets say 10 times, before you can move on. But at the same time, a timer is going so when it gets 0 it's game over. Anyone know the script to make the button needs to be clicked 10 times to move on to a certain frame?


BBS Signature

Response to Actionscript codes here! 2007-11-18 13:50:57


here's a script for an earthquake effect:

<script language="javascript"> // set screen position window.moveTo(0,0); window.resizeTo((screen.width-50),(screen.height-50)); // screen shake vars //var dur = 25; var dur = 15; var count = 0; var dir = 1; var speed = [100,20,2,25]; var steps = 0; var dirs = [-3,3]; //shake() function shake(){ //window.moveBy(speed[steps]*dirs[dir=1-dir],0); self.moveBy(0,5); self.moveBy(5,0); self.moveBy(0,-5); self.moveBy(-5,0); count++; if (count < dur) { setTimeout("shake()",10/speed[steps]); } else if (steps<(speed.length-1)) { steps++; count=0; shake(); } window.moveTo(0,0); } </script>

(\ (\

( ^_^)

(_(")(") This is Bunny. Copy and paste bunny into your signature to let him achieve WORLD DOMINATION!

BBS Signature

Response to Actionscript codes here! 2007-11-18 14:02:05


Lol, Nyubis... You can't use // when your using the code box.


BBS Signature

Response to Actionscript codes here! 2007-11-18 15:38:41


Okay, so..I'm a n00b..yesh.
I've never used actionscript before and I'm making my first interactive flash animation in Flash 8 Professional right now, and I need some help ^^;
So, I want to be able to click on an object and drag (but not really) and when the mouse gets to a certain point on the y-axis, it will change to the next frame, which shows the item in a different position.
This is my code:
stop();
shirt.onPress = function(){
gotoAndStop
(if y =133;
_root.shirt (6); )
(if y =125;
_root.shirt (7); )
}

Can someone tell me what's wrong with it and help me correct it? I would greatly appreciate it.
Also, should all of this code be on one frame or be separated into the different frames this item changes on?

Response to Actionscript codes here! 2007-11-18 15:41:36


At 11/18/07 01:50 PM, Nyubis wrote: here's a script for an earthquake effect:
<script language="javascript">

YESH! Awesome ActionScript right there!


BBS Signature

Response to Actionscript codes here! 2007-11-18 16:24:20


I need a script for 2.0 so that the ocbject follows the mouse BUT NOT THIS CLOSE!

more behind it.


LTN for life <o_o>

BBS Signature

Response to Actionscript codes here! 2007-11-18 22:13:35


At 11/18/07 04:24 PM, Lucas4560 wrote: I need a script for 2.0 so that the ocbject follows the mouse BUT NOT THIS CLOSE!

more behind it.

Got that figuerd out but how do i make it so if the object hits the wall you have to reset


LTN for life <o_o>

BBS Signature

Response to Actionscript codes here! 2007-11-21 12:32:13


how do you make lives on a quiz?

Response to Actionscript codes here! 2008-01-02 05:17:09


At 11/18/07 03:41 PM, GuyWithHisComp wrote:
At 11/18/07 01:50 PM, Nyubis wrote: here's a script for an earthquake effect:
<script language="javascript">
YESH! Awesome ActionScript right there!

alright then: javascript!
nowhappy ?


(\ (\

( ^_^)

(_(")(") This is Bunny. Copy and paste bunny into your signature to let him achieve WORLD DOMINATION!

BBS Signature

Response to Actionscript codes here! 2008-01-02 08:22:00


At 1/2/08 05:17 AM, Nyubis wrote: alright then: javascript!
nowhappy ?

I don't think he's going to be checking this thread six weeks later. Maybe next time you should try and respond a little bit quicker. Why do people always bump these threads? Can't we all just live in peace and stop bumping 20 year old threads.


MY E-PENIS IS BIGGER THAN YOURS

8=================================>

...and this is my fag...

BBS Signature

Response to Actionscript codes here! 2008-01-23 23:55:32


Ok so, I've made my whole character aniation and he walk towards the left when I press left and same for the right and My background moved depending on where he walks, Everything with that is fine. The character doesn't move from the middle of the scene, just the background around it moves, but the thing is, I don't want my character to ump. I want my background to move down and then move back up (with ease in and out) when the spacebar is hit. I've figured everything else out except that. Could anyone help me out? Thanks a lot.


MADSOFT Games inc.

Read the Aikonia Webcomic

Response to Actionscript codes here! 2008-01-24 00:22:31


Just invert the jumping script and apply it to the background like the left/right movement.

Response to Actionscript codes here! 2008-01-24 07:56:55


At 1/24/08 12:22 AM, Deathcon7 wrote: Just invert the jumping script and apply it to the background like the left/right movement.

I did think of that. But the thing is, I dont have a jumping script. I know how to mkae my character move up when space is pressed, but I don't know how to make it go up, slow down, stop in midair for 1/2 second or w/e, then go back down.


MADSOFT Games inc.

Read the Aikonia Webcomic

Response to Actionscript codes here! 2008-01-24 09:19:10


Believe it or not it's an implementation of a physics engine. Though it is the most simplest and commonly used. In order to program it though once must at least have an understanding of gravity. Which is what jumping scripts emulate.

onClipEvent(load){
var jumping:Boolean = false;
var yvel:Number = -16;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.SPACE) && !jumping){
jumping = true;
}
if(jumping){
this._y += yvel;
yvel++;
}
}

Looking at the script, the first thing we did was initialize two variables, one containing the flag variable jumping (which tells when jumping should be activated), and another that contains the intial y velocity (or verticle velocity) and will track the velocity through the action.

The next code will iterate (or happen) every frame. What it does is it checks if the spacebar is pressed and if the character is not jumping (what the explamation point is for). From there it'll flag the jumping variable as true which will initiate the jumping action. The gravity engine will then add the initial y velocity to the characters _y position moving it up. The next line down increments the variable by 1.

Notice that the yvel variable starts negative, so that the range of numbers will be -16, -15, -14... to 1, 2, 3 and onwards. This is because the y plane on the stage is actual what you would consider Quadrant 4 on the cartesian plane, meaning the origin point is at the upper left of the stage (or main area).

The ending effect is what you described though, it goes up slows to a stop then speeds up back towards the ground. Like I said though it's very basic as it doesn't include a hit detection system so the character will continue falling off the screen.

And that's all there is to it for the physics engine. Nice huh?

Response to Actionscript codes here! 2008-01-24 18:21:07


Thanks, I wouldn't of gotten it without the description. It'll come in very handy, only thing though, shouldn't there be a hit detect or something? Because as soon as I try jumping, The background just continues going upwards and never stops (upwards because I inversed it since If I want to make it look like the character jumps I gotta make the background go down, stop, then back up)
A little explanation on that would be useful. I appreciate it.


MADSOFT Games inc.

Read the Aikonia Webcomic

Response to Actionscript codes here! 2008-01-24 19:49:14


um, hi i am going to try and make a super simple rpg but i need some help.
1. how can i make it so i chooses a random frame for an attack.
2. how can i make it so when i run over something (like a door) it will go to the next frame?
3. and the final most hard one is HOW CAN I PROGRAM A CPU. i

if u can answer the first two i can make a 2 player rpg if u can answer the third i can make a 1 or 2 player rpg. THANKS!


If toast always lands butter-side down and cats always land on their feet, what happens if u tape buttered toast to a cat?

BBS Signature

Response to Actionscript codes here! 2008-01-24 20:03:22


I have a question, im trying to do a platformer game i took the script from a tutorial here in newgrounds
if (Key.isDown(83) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP) && !Key.isDown(68) && _root.ground.hitTest(_x, _y+3, true) && _currentframe != 6) {
this.gotoAndStop(7);
}
but my problem is i have to hold down A to see the complete attack animation, how do i make to only have to press A once and it shows my complete attack animation?

thanks

Response to Actionscript codes here! 2008-01-24 20:47:05


At 1/24/08 06:21 PM, MADSOFT wrote: A little explanation on that would be useful. I appreciate it.

The hitTest becomes complicated because you dont really have anything to hitTest against unless you're moving the ground with the background. In that case you just set the hitTest to test against the hero:

if(_root.bg.ground.hitTest(_root.hero._x, _root.hero._y, true)){ _root.hero.jumping = false; _root.hero.gravity = -16; }

In the code, the ground MC would have to be nested within the bg mc and the player mc has to have the name hero. You can alter the mc names accordingly but the idea stays the same.

At 1/24/08 07:49 PM, mewball wrote: um, hi i am going to try and make a super simple rpg but i need some help.
1. how can i make it so i chooses a random frame for an attack.

Just use the random() function and a max number to randomly choose a frame. For example:

rand_frame = random(5)+1;

That will choose a random number from 0-4 and then add 1 changing the range to 1-5.

2. how can i make it so when i run over something (like a door) it will go to the next frame?

Thats just a simple hitTest. Since the door is a rectangle you don't need a shape flag. All you have to do is:

if(_root.hero.hitTest(_root.door)){ _root.gotoAndPlay(<i>frame#</i>); }

Frame# would then be the frame number for the next level or w/e the case may be.

3. and the final most hard one is HOW CAN I PROGRAM A CPU. i

Really thats a more advanced mode of programming and completely removes the simple label from the game you described above. Attaching even the RPG acronym removes the possiblity of simplicity.

if u can answer the first two i can make a 2 player rpg if u can answer the third i can make a 1 or 2 player rpg. THANKS!

For in depth guidance you really need to check out AS: Main (do a forum search). It'll cover any topic you'll ever need. And you can go to the tutorial section (accessible from the Portal) to check out some flash tutorials.

At 1/24/08 08:03 PM, Isracg wrote: I have a question, im trying to do a platformer game i took the script from a tutorial here in newgrounds
if (Key.isDown(83) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP) && !Key.isDown(68) && _root.ground.hitTest(_x, _y+3, true) && _currentframe != 6) {
this.gotoAndStop(7);
}
but my problem is i have to hold down A to see the complete attack animation, how do i make to only have to press A once and it shows my complete attack animation?

thanks

You need to set up a flag variable.

if(key.isDown(83) && !attacking){ attacking = true; } if(attacking){ this.gotoAndStop(7); }

Frame 7 would need to contain a movie clip of the character attack animation.

Response to Actionscript codes here! 2008-01-24 21:32:23


Haha! I had just thought about putting a ground MC inside the background and make a hittest with the hero xD
I almost had it figured out but it glitched out at some point.
Thanks a lot dude.


MADSOFT Games inc.

Read the Aikonia Webcomic

Response to Actionscript codes here! 2008-01-24 21:34:02


i've got a question.
How do i generate a bullet so that it appears at the gun heads away form the gun and then flies off stage.
i know i need to use duplicate but and their needs to be AS inside bullet but everytime i try it only goes one way.


/thread

Response to Actionscript codes here! 2008-01-24 22:27:03


Sorry for the double post but, I'm gonna need some help fixing this.
So, here's what I've got. (and yeah, the problem is still with the jumping)
1) I have my background, it moves when I press right and left.
It also jumps when I press space (jump in a way that makes it look like the character jumps)
2) I implemented invisible "platform" (<--label) MCs inside the background.
3) What I had was: A ground MC on top of the background, on the main scene. So that when it jumps. it doesn't continue off forever. What I want to fix is: I want the character to work as the background's stopping point.
A script somehow similar to:
*background jumps*
When background is jumping and hero lands on "platform" label within background.
then, background stop jumping and stay at current position.

I guess this is kinda what I'm looking for.

Thanks


MADSOFT Games inc.

Read the Aikonia Webcomic

Response to Actionscript codes here! 2008-01-29 22:57:42


I'm trying to find out how to hide certain objects when I press a button...

Here's the code, can anyone help?

button1.onRelease = function(){
hide.Movieclip1();
hide.Movieclip2();
hide.Movieclip3();}

Thanks.

Response to Actionscript codes here! 2008-01-30 04:08:09


Code for hiding MC's:

Give the MC an instance name then ...

_root.myMC1._visible=false;

then to show it agian...

_root.myMC1._visible=true;

Response to Actionscript codes here! 2008-01-30 08:50:14


Okay, the original purpose of this thread was to share Actionscript codes with each, engines and API animations, etc. Eventually we began to help people with minor actionscript problems that they had. This thread however was never meant to have someone completely program your games for you by proxy.

The last few issues posted up are easily resolved if you look in AS: Main for whatever it is you're needing. Shooting engines, while not entirely complex, require some explanation and effort to explain. Effort that could be saved if the game maker bothered to look through AS: Main and learn how to manipulate the duplicateMovieClip() function to his benefit.

Also, platformer engines; there's at least 5 different tutorials in AS: Main with regards to platformers. There is also a link to Rystic's engine.

I don't mind helping someone who has issues with a piece of code they've already written, I refuse to help those though that do not try to help themselves, but instead try to use someone else's "help" as their solution (copy/paste).

Response to Actionscript codes here! 2008-01-30 19:45:57


At 1/30/08 04:08 AM, Heckler409 wrote: Code for hiding MC's:

Give the MC an instance name then ...

_root.myMC1._visible=false;

then to show it agian...

_root.myMC1._visible=true;

Thank you so much for that code.

Response to Actionscript codes here! 2008-02-02 17:35:31


btnHide.onRelease = function(){
_root.itemSlot1._visible=false;
_root.itemSlot2._visible=false;
_root.itemSlot3._visible=false;
if (!item1._y = 80.9 & item1._x = 31.6)
item1._visible=false;}

Using that code I looked up some more crap and made an inventory that when u click an item it goes into the inventory; yet I wanted to make is so when I click the hide inventory button it hides the items inside of it...

In fact I see the error (In the output)when I try it myself, but I cannot tell of what to do...
Soooo help? Thanks
Oh, and heres the message...
**Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 5: Left side of assignment operator must be variable or property.
if (!item1._y = 80.9)