00:00
00:00
Newgrounds Background Image Theme

BrunoVugl 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,560 Views | 7,981 Replies
New Topic

Response to Actionscript codes here! 2003-12-23 15:59:02


At 12/23/03 03:49 PM, ryanryan wrote: CAn you guys answer me--->!#$@!##@!$!<-----SWearing!

you gotta understand that there is no one script for stuff like that. it has to apply to your game, but it'd look like this.

on (release) {
health--;
}

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


How would i make it so that a computer controled car follows your car but faces the right way acording to the street. Then if you get to a certain place it goes back to the baddies base.

Response to Actionscript codes here! 2003-12-23 16:35:03


At 12/23/03 04:22 PM, mexxa wrote: How would i make it so that a computer controled car follows your car but faces the right way acording to the street. Then if you get to a certain place it goes back to the baddies base.

please dont ask questions like these, it really just depends on how your game works, you'd need to link us to a .fla of your game so that we could help you.

Response to Actionscript codes here! 2003-12-23 16:40:03


I dont have any-webspace to make it s people cn download the .fla. I can get the script if you want.

Response to Actionscript codes here! 2003-12-24 00:23:53


i have 2 movie clips one called guy and one called enemy... i have a dynamic text box labeled lives and when enemy hits guy the lives go down obviously... i got that far but when lives = zero i want it to go to frame 2 of the movie heres my actionscripts so far
-------------------------------------------------------------------
// ENEMY HITTEST
onClipEvent (enterFrame) {
if (this.hitTest(_root.enemy)) {
_root.lives--;
if(lives==0)
_root.gotoAndStop(2);
}
}
------------------------------------------------------------------
can anyone tell me what im doing wrong?

Response to Actionscript codes here! 2003-12-24 04:18:49


You need an if statement using if lives=0 gotoandplay(frame with death in).

Response to Actionscript codes here! 2003-12-24 04:19:56


Oops i didnt read you post very well, instead of a second if put else if.

Response to Actionscript codes here! 2003-12-24 09:42:55


Im back from 3 days vacation.


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-24 09:53:15


At 12/24/03 09:42 AM, eviLudy wrote: Im back from 3 days vacation.

How would i make it so that a computer controled car follows your car but faces the right way acording to the street. Then if you get to a certain place it goes back to the baddies base.The code i use for your car is:

onClipEvent (enterFrame) {
// right
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation+move;
}
// left
if (Key.isDown(Key.LEFT)) {
_rotation = _rotation-move;
}
// up
if (Key.isDown(Key.UP)) {
if (move<40) {
move++;
}
} else if (move>0) {
move--;
}
// down
if (Key.isDown(Key.DOWN)) {
if (move>-10) {
move--;
}
} else if (move<0) {
move++;
}
// enter
if (Key.isDown(Key.ENTER)) {
_x = 200;
_y = 200;
_rotation = 0;
move = 0;
}
// _x & _y position
if (_rotation>180) {
_y = _y+(move*Math.cos(Math.PI/180*_rotation));
_x = _x-(move*Math.sin(Math.PI/180*_rotation));
}
if (_rotation<180) {
_y = _y-(move*Math.cos(Math.PI/180*_rotation));
_x = _x+(move*Math.sin(Math.PI/180*_rotation));
}
_root.speed = move*3;
}

Response to Actionscript codes here! 2003-12-24 10:05:25


At 12/24/03 09:53 AM, mexxa wrote:
How would i make it so that a computer controled car follows your car but faces the right way acording to the street. Then if you get to a certain place it goes back to the baddies base.The code i use for your car is:

onClipEvent (enterFrame) {
// right
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation+move;
}
// left
if (Key.isDown(Key.LEFT)) {
_rotation = _rotation-move;
}
// up
if (Key.isDown(Key.UP)) {
if (move<40) {
move++;
}
} else if (move>0) {
move--;
}
// down
if (Key.isDown(Key.DOWN)) {
if (move>-10) {
move--;
}
} else if (move<0) {
move++;
}
// enter
if (Key.isDown(Key.ENTER)) {
_x = 200;
_y = 200;
_rotation = 0;
move = 0;
}
// _x & _y position
if (_rotation>180) {
_y = _y+(move*Math.cos(Math.PI/180*_rotation));
_x = _x-(move*Math.sin(Math.PI/180*_rotation));
}
if (_rotation<180) {
_y = _y-(move*Math.cos(Math.PI/180*_rotation));
_x = _x+(move*Math.sin(Math.PI/180*_rotation));
}
_root.speed = move*3;
}

You gotta label your own car PLAYER and put this script in the char that chases you...


onClipEvent (enterFrame) {
clipToFace = _root.player;
xdiff = clipToFace._x-_x;
ydiff = clipToFace._y-_y;
offset = 0;
_rotation = Math.atan2(ydiff, xdiff)*180/Math.PI+offset;
}
onClipEvent (enterFrame) {
this._y += ydiff / 20;
this._x += xdiff / 20;
}

I tested it


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-24 10:12:15


That would work if a heli copter was chasin you but the car has to stay the right way acording to the street so i doesn't drive straight into the side of a building. I also need the street boundries for the car.

Response to Actionscript codes here! 2003-12-24 10:23:22


At 12/24/03 10:12 AM, mexxa wrote: That would work if a heli copter was chasin you but the car has to stay the right way acording to the street so i doesn't drive straight into the side of a building. I also need the street boundries for the car.

I dont get wot u mean.... Can u show some sort of Example or explain whitout hard words for a 13 year old dutch boy

:-)


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-24 10:26:41


Say you have your car following another in a city like inviroment, i need a script so that the car following you doesn't face towards you but the right way acoring to the street. So if the street goes north and you at the end you turn west the enemy still faces north until it gets to the turning point.

Response to Actionscript codes here! 2003-12-24 10:29:32


At 12/24/03 10:26 AM, mexxa wrote: Say you have your car following another in a city like inviroment, i need a script so that the car following you doesn't face towards you but the right way acoring to the street. So if the street goes north and you at the end you turn west the enemy still faces north until it gets to the turning point.

That would change the script I gave you into this....


onClipEvent (enterFrame) {
clipToFace = _root.player;
xdiff = clipToFace._x-_x;
ydiff = clipToFace._y-_y;
offset = 0;
}
onClipEvent (enterFrame) {
this._y += ydiff/20;
this._x += xdiff/20;
}


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-24 10:53:52


That script ust made it so that the car faced one way and didnt change the way it faed at turns or no roads that didnt face that way.

Response to Actionscript codes here! 2003-12-24 20:15:34


Consider this your Christmas present:

x = [];
y = [];
i = 1;
this.onMouseDown = function() {md = true;};
this.onMouseMove = function() {
if (!md) {
x.push(_xmouse);
y.push(_ymouse);
updateAfterEvent();
}
};
this.onEnterFrame = function() {
if (md) {
if (i < x.length) {
this.createEmptyMovieClip("ln" + i, i);
with (this["ln" + i]) {
_alpha = 0;
lineStyle(1, 0x000000);
moveTo(x[i - 1], y[i - 1]);
lineTo(x[i], y[i]);
this["ln" + i].onEnterFrame = function() {
_alpha += 5;
if (_alpha >= 100) {
delete this.onEnterFrame;
}
};
}
i++;
}
}
};

Move your mouse around the screen for a bit, then click... the lines fade in. I recommend 20fps.

Response to Actionscript codes here! 2003-12-24 22:02:11


Nice script CrookedAsterisk,
I was wondering if someone would help me out with a game engine Im working on.... I have an MC, with the linkage name of "house1" and an instance name "house1", And I have a button with :
on (release) {
attachMovie("house1", "house", 10);
_root.house.startDrag(true);
}

Then in the houses AS I have :
onClipEvent (mouseDown) {
this.stopDrag();
}

Now what that does is when you click on the button It takes the House MC, Now the Problem is I want it so that If you click on the button It will create another house MC without deleting the first? Hopefully I explained myself well enough :)


- 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-12-25 00:52:12


n00b question here.

i want to label an mc i have, but i cant find were to label it.
i go into the mc's properties, but there is nothing that has to do with label, and i have changed the name and all, bu it dosnt work.

btw, im using flash 5 if it makes any difference,

Response to Actionscript codes here! 2003-12-25 02:50:57


At 12/25/03 12:52 AM, Yoshit wrote: n00b question here.

i want to label an mc i have, but i cant find were to label it.
i go into the mc's properties, but there is nothing that has to do with label, and i have changed the name and all, bu it dosnt work.

btw, im using flash 5 if it makes any difference,

change the instance name... it's somewhere in there, i havent used flash 5 for about a year, so i cant really remember it... get mx. btw, nice sig, i love conkers... i never knew there was a conkers crew.

Response to Actionscript codes here! 2003-12-25 04:48:07


people.... my christmas gift is coming up. I'm creating A tutorial that has been asked for around.... 25 pages ago... just u wait

Merry Christmas!


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-25 06:02:08


Ok so there's a lot of people that keep asking questions that have been awnsered a lot of times B4


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

Dressup items:
_____________________________________

For every item of clothes you want to have draggable do this

Make the item a button
Put these actions in the button:
on (press) {
startDrag ("");
}
on (release) {
stopDrag ();
}

basic car
__________________________________

onClipEvent (enterFrame) {
// right
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation+move;
}
// left
if (Key.isDown(Key.LEFT)) {
_rotation = _rotation-move;
}
// up
if (Key.isDown(Key.UP)) {
if (move<8) {
move++;
}
} else if (move>0) {
move--;
}
// down
if (Key.isDown(Key.DOWN)) {
if (move>-10) {
move--;
}
} else if (move<0) {
move++;
}
// enter
if (Key.isDown(Key.ENTER)) {
_x = 200;
_y = 200;
_rotation = 0;
move = 0;
}
// _x & _y position
if (_rotation>180) {
_y = _y+(move*Math.cos(Math.PI/180*_rotation));
_x = _x-(move*Math.sin(Math.PI/180*_rotation));
}
if (_rotation<180) {
_y = _y-(move*Math.cos(Math.PI/180*_rotation));
_x = _x+(move*Math.sin(Math.PI/180*_rotation));
}
}

INVENTORY SCRIPT
___________________________________
You need to create global booleans that, when true, will cause certain movie clips and buttons be visible.
I'm not absolutely sure this will work with nested buttons and/or movie clips, since I've tried similar things and had them not work for reasons unexplained.... Well, anyway, I'd suggest making a movie clip of the subscreen you want, and inside it have all the items. In the actionscript for the movie clip put stuff like:

this.item1_instance_name._visible = false;
this.item2_instance_name._visible = false;
this.item3_instance_name._visible = false;

if(haveItem1 == true){this.item1_instance_name._visible = true;}
if(haveItem2 == true) {this.item2_instance_name._visible = false;}
if(haveItem3 == true) {this.item3_instance_name._visible = false;}

//where "haveItem1" is the name of a global boolean that will initially be false, but will be toggled to true when you pick up the item.

Then in the main stage there could be a button that would have the actionscript:

on(release){
if(_root.subscreen_movieclip._visible == false){_root.subscreen_movieclip._visible = true}
else{_root.subscreen_movieclip._visible = false}
}

Don't forget to name your instances of each movie clip.

Movieclip runs away from mouse
__________________________________________

onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse,_root._ymouse,true)) {
this._x = int(Math.random()*550);
this._y = int(Math.random()*400);
}
}

SCORE SCRIPT
_____________________________________
onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.score += 1;
if (_root.score == 100) {
_root.gotoAndPlay (frame);
}
}
}
RPG INVENTORY SCRIPT
_____________________________________

Add this code to the item clip:
onClipEvent (enterFrame) {
if (_root.character.hitTest(this)) {
_root.addToslot(this);
}
}
The player that walks around controlled by the user should be labelled Character and the box where the icon of the item comes should be lebelled slot

Random Appearance
__________________________________________

onClipEvent(load) {
chanceOfAppearing = 10;
chance = 0;
}

onClipEvent(enterFrame) {
chance++;
if (Random(chanceOfAppearing) < chance) {
this._x = Random(550);
this._y = Random(400);
chance = 0;
} else {
this._x = -100;
}
}

Random Wandering
_____________________________________________
onClipEvent(load) {
wanderAmount = 300;
leftLimit = 10;
rightLimit = 540;
chanceOfJump = 50;
xPosition = 275;
speed = 10;
chanceOfChange = 0;
}

Gun Tutorial
________________________________
First you make a movie clip, that shows the gun and put it on the bottom of the flash Document, then put this code in the actions of the gun:

onClipEvent (enterFrame) {
this._x = _root._xmouse += 20;
}

Then you make an laser dot, wich is the dot the gun aims to automaticly, and also make it a movieclip. Then put this code into the laserdot movieclip:

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

Jumping Script

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

Be sure to label the ground mc GROUND

That wos an X-mas gift for the people that haven't checked the first page...


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-25 06:32:28


dose anyone know how to make ammo for a gun game??

Response to Actionscript codes here! 2003-12-25 06:38:11


At 12/25/03 06:32 AM, gun2gun wrote: dose anyone know how to make ammo for a gun game??

I do,
piece of cake vut I cant tell you untill you told me...

What kind of shooting game
What the shooting script is


Swing a Little more!

.. ROCK OUT!

BBS Signature

Response to Actionscript codes here! 2003-12-25 16:32:34


At 12/25/03 06:02 AM, eviLudy wrote: Lots of codes.

Those are some nice codes you got there, Ludy.

this.item1_instance_name._visible = false;
this.item2_instance_name._visible = false;
this.item3_instance_name._visible = false;

if(haveItem1 == true){this.item1_instance_name._visible = true;}
if(haveItem2 == true) {this.item2_instance_name._visible = false;}
if(haveItem3 == true) {this.item3_instance_name._visible = false;}

//where "haveItem1" is the name of a global boolean that will initially be false, but will be toggled to true when you pick up the item.

I've said before, but this is a classic example of people using unnecessary “if” statements.

Everyone seems to think that the equality operator is only for “if” statements. Well, it’s not just for that. The equality operator returns a Boolean.

So, instead of:

this.item1_instance_name._visible = false;
this.item2_instance_name._visible = false;
this.item3_instance_name._visible = false;

if(haveItem1 == true){this.item1_instance_name._visible = true;}
if(haveItem2 == true) {this.item2_instance_name._visible = true;}
if(haveItem3 == true) {this.item3_instance_name._visible = true;}

It would be easier to do it this way:

this.item1_instance_name._visible = haveItem1 == true;
this.item2_instance_name._visible = haveItem2 == true;
this.item3_instance_name._visible = haveItem3 == true;

OR

for (j = 1; j <= 3; j++) this["item" + j]._instance_name._visible = eval("haveItem" + j);

Response to Actionscript codes here! 2003-12-25 16:35:58


At 12/25/03 06:32 AM, gun2gun wrote: dose anyone know how to make ammo for a gun game??

It real does depend on what kind of methods you are using to shoot...

if (ammo > 0) shoot();
// Lol

Response to Actionscript codes here! 2003-12-25 16:56:39


Here's a code for getting the connection rate (kb/s) when a movie is loading:

checkInterval = 500;
updateRate();
function updateRate() {
rate = Math.round(((_root.getBytesLoaded() - oldBL) / checkInterval) * 10) / 10;
oldBL = _root.getBytesLoaded();
updateAfterEvent();
}
var checkRate = setInterval(updateRate, checkInterval);

And this is for when you want it to stop:

clearInterval(checkRate);

Response to Actionscript codes here! 2003-12-25 20:07:00


I did a quick search on a integer to hexadecimal function on this forum, and I didn't see anything. So, here is my integer to hexadecimal function. It was coded while I had a fever (so damn sick!)

function int2hex(i){

var h = "";

while (i > 0){

if(i%16 > 9)
h = String.fromCharCode(i%16+55)+h;
else
h = String(i%16)+h;

i = Math.floor(i/16);
}

return h;

}

Pretty simple eh ^_^

Assign a string variable to the function to get results. Time duration is between 1-2 ms, averaged over 5 cases on a P4 2.4 GHz laptop. integer tested had 16 places. It only works for integer values only; inputting a float value will have the fractional end snipped off.

Slight modifications can be made to incorporate the fractional part of a float, but I made this code for my color selector for my project, and hence I don't care for the float case.

Response to Actionscript codes here! 2003-12-25 20:40:13


what does this do:
on (press) {
startDrag ("");
}
on (release) {
stopDrag ();
}

Response to Actionscript codes here! 2003-12-25 20:44:11


This is a "symbolic" code piece that allows the user to drag a movie clip from one position on the stage to another; it is usually determined by mouse coordinates, or some other fancy mathematical measures.

Response to Actionscript codes here! 2003-12-25 20:55:04


i dont know anything about action scripting :( can you give me a link you a site that explanes in plain english action scripts, an not flashkit .