Forum Topic: Actionscript codes here!

(210,502 views • 8,558 replies)

This topic is 286 pages long. [ 136 | 7 | 8 | 9 | 10148286 ]

<< < > >>
None

gasthatsmells

Reply To Post Reply & Quote

Posted at: 7/8/03 06:21 AM

gasthatsmells LIGHT LEVEL 11

Sign-Up: 12/30/02

Posts: 52

I know how to make a movie clip follow a mouse. But how do I take it off. I want the cursor to show on one seen, and be gone on another. How would I do that?


Questioning

Need-More-Sugar

Reply To Post Reply & Quote

Posted at: 7/8/03 06:33 AM

Need-More-Sugar NEUTRAL LEVEL 05

Sign-Up: 02/27/03

Posts: 46

i have 4 pictures that i need to apply to make a walkabout. they are final fantasy one sprites so ill call them:

fightR1
fightR2
fightL1
fightL2

i need to set it up so that whenever i press right, it changes to fightR1 and moves a little bit and if i press it again it changes to fightR2 and moves another little bit. i need the same with left. i will also need to make the spacebar use the sword but once i get the walking done i can figure that out myself. be aware that im using flash 5 for this so dont use anything unique to MX please. thanks.


None

AngryBinary

Reply To Post Reply & Quote

Posted at: 7/8/03 06:38 AM

AngryBinary EVIL LEVEL 06

Sign-Up: 02/18/03

Posts: 255

That depends on the code you used to make the clip follow the mouse, really. First of all, you have to

Mouse.show();

or something to that effect...

Then, you either 'null;' the function you have set to make the clip follow the mouse (clip.customFollowMouseFunction = null;), and/or just remove the clip from the scene (clip.removeMovieClip();)


None

un-mediocre

Reply To Post Reply & Quote

Posted at: 7/8/03 10:33 AM

un-mediocre NEUTRAL LEVEL 08

Sign-Up: 12/31/01

Posts: 184

I am the worst action scripter in the world, and I find this post awesome.

I have a couple of questions:-

1) I created a moveable person using this code:
onClipEvent (load) {
// Set the move speed
moveSpeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
this.gotoAndStop(1);
// Move Right
} else if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
this.gotoAndStop(2);
// Move Up
} else if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
this.gotoAndStop(3);
// Move Down
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
this.gotoAndStop(4);
// Move Left
}
}

He won't stop moving his feet when he is not walking. How can I fix that?

2) Using this same MC, I want him to shoot a fireball when you press spacebar at the direction he is looking at.


None

Elementsk8er506

Reply To Post Reply & Quote

Posted at: 7/8/03 02:13 PM

Elementsk8er506 NEUTRAL LEVEL 11

Sign-Up: 07/23/02

Posts: 117

hey i was wondering how to make walls or objects that you cannot pass through such as mario needing to jump over a tube to pass it in a game.

one more question is how do i make a character go through doors or once he gets to a certain point it can change scenes or something?

this will be greatly appreciated if you answer. c ya.


None

raidennrls

Reply To Post Reply & Quote

Posted at: 7/8/03 03:17 PM

raidennrls NEUTRAL LEVEL 03

Sign-Up: 02/23/03

Posts: 26

does anyone know a hittest script so my car bounces off a wall when it hits it..thanks


None

AngryBinary

Reply To Post Reply & Quote

Posted at: 7/8/03 09:03 PM

AngryBinary EVIL LEVEL 06

Sign-Up: 02/18/03

Posts: 255

Using the code you already have, all you have to do is add an additional "else" statement to send the character back to the idle frame when nothing is being pressed:


onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
this.gotoAndStop(1);
} else if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
this.gotoAndStop(2);
} else if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
this.gotoAndStop(3);
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
this.gotoAndStop(4);
} else {
this.gotoAndStop("idleFrame");//whatever it is
}

}

Ok, so you're saying he's not gonna be facing the direction he was walking when he goes to the idle frame. Well, how does Flash know which way he was facing? You have to supply that info! Then we can tailor Idle frames to do that.

First, gather information about which way you're facing as you change directions (using -1/0/+1 variables for vertical/horizontal directions makes for easily written fireball && movement code, and a text variable for direction allows you to jump around frame labels with ease). So, label the walking frames "walkup", "walkdown", "walkleft", and "walkright". Then create four idle frames, "idleup", "idledown", "idleleft", "idleright". Keep the first frame blank and empty, however, as it's a good place to put code you only want to run once (i.e, function definitions), as you will never have to go back to it.

As long as i'm at it, i'm going to change the code you have to work INSIDE the MC as opposed to on top of it, so it'd be inside the MC's 'Frame Actions' instead of in the 'Movie Clip Actions' outside the MC. It's a good practice for game making to do MC's this way.
Plus, it allows you to more easily define different codes for idle frames and walking frames, something i find almost a necessity.

moveSpeed = 10;
dir = "right"; //just some inits
horiz = 1;
vert = 0;
this.onEnterFrame = idle; //begin with idle code

//here's the idle code. it basically just waits until
//a key is pressed to do something.

function idle(){
if (Key.isDown(Key.UP)||Key.isDown(Key.DOWN)
||Key.isDown(Key.LEFT)||Key.isDown(Key.RIGHT)){
this.onEnterFrame = walk; //start walk code
}
}

//here's the function code for walking. it should
//move the clip and check to make sure that a key is down:

function walk() {
if (Key.isDown(Key.RIGHT)) {
horiz = 1; //facing positive X direction
vert = 0; //facing neutral Y direction
dir = "right";
} else if (Key.isDown(Key.UP)) {
horiz = 0; //facing neutral X direction
vert = -1; //facing negative Y direction
dir = "up";
} else if (Key.isDown(Key.DOWN)) {
horiz = 0; //neutral X direction
vert = 1; //positive Y direction
dir = "down";
} else if (Key.isDown(Key.LEFT)) {
horiz = -1; //negative X direction
vert = 0; //neutral Y direction
dir = "left";
} else {
this.gotoAndStop("idle" + dir);//automatically goes to the correct frame!!
this.onEnterFrame = idle;//back to idle code
}
this._x += moveSpeed * horiz;
this._y += moveSpeed * vert;
gotoAndStop("walk" + dir); //again, goes to the correct frame
}
gotoAndStop("idle" + dir);//leave the first frame, and never come back

Fireballs? I'll put that in a seperate post, since this one is getting rather lengthy, bear with me.


None

AngryBinary

Reply To Post Reply & Quote

Posted at: 7/8/03 09:52 PM

AngryBinary EVIL LEVEL 06

Sign-Up: 02/18/03

Posts: 255

Now, sure, we can make a fireball that is perfectly round so you can shoot it in any direction with the same code. But, since you've already gathered all this info about which way your character is facing... why can't you use the same code to make it fire in different directions? Well of course you can.

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. This way, the dir variable you already have can be ported directly to the fireball. Now here's the code you put in frame one:

moveSpeed = 15; //or whatever speed you want
dir = _parent.dir; //retrieve variables from character clip
horiz = _parent.horiz;
vert = _parent.vert;
lifeSpan = 50; //fireball life span, in frames
age = 0; //fireballs life span counter

//defining functions makes for easily alterable and legible code

function fireBallMove(){
age++;
hitCheck();
if (age > lifeSpan){
this.onEnterFrame = null;
gotoAndPlay("destroy");
}
this._x += moveSpeed * horiz;
this._y += moveSpeed * vert;
}

function hitCheck(){
//hitTest code here, i'll just make something up
if (this.hitTest(enemy)){
enemy.gotoAndPlay("takeDamage");
this.onEnterFrame = null;
gotoAndPlay("destroy");
}
}

this.onEnterFrame = fireBallMove();
gotoAndStop(dir);

The "destroy" frame will be the first frame of an animation sequence that will remove the fireball from the screen. On the last frame of this sequence, there should be this action:

this.removeMovieClip();

Now, to make this fireball come into play, you have to attach it to the screen... somehow... Start out by Exporting the fireball MC:

Right click on the fireball in the Library Panel, select 'Linkage', and check 'Export for actionscript' (and 'Export in first frame'). Give it an identifier name like "fireBall". Now, stick this code in the Character MC, in both the 'idle' and 'walk' functions:


if (Key.isDown(Key.SPACE)){
layer++; //important! reusing layers will destroy other clips
this.attachMovieClip("fireBall", "fireBall" + layer, layer);
layer++; //maybe i'm a little OC, but i always increment layers twice
}

That'll attach the clip to the movie. Since all the scripts the fireball needs to move and work are in the fireball clip, you don't have to worry about doing anything else to it.


None

subtlerobot

Reply To Post Reply & Quote

Posted at: 7/8/03 10:25 PM

subtlerobot LIGHT LEVEL 06

Sign-Up: 02/20/03

Posts: 7

I eed the script for making a zooming sniper scope, as seen in Scope Assault .
Please, I need help.

Actionscript codes here!


None

ninjadeath

Reply To Post Reply & Quote

Posted at: 7/8/03 10:30 PM

ninjadeath NEUTRAL LEVEL 03

Sign-Up: 11/09/02

Posts: 16

At 7/8/03 03:17 PM, raidennrls wrote: does anyone know a hittest script so my car bounces off a wall when it hits it..thanks

I left out a good deal of this script, mainly because it invloves the inclusion of my entire collision engine. But heres a piece of it:

in the actions panel of the car's movie clip:
onClipEvent (enterFrame) {
pow = 0.2;
max = 20;
dec = 0.7;
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation + 10;
} else if(Key.isDown(Key.LEFT)) {
_rotation = _rotation - 10;
}
if (Key.isDown(Key.UP)) {
rot = _rotation;
thisSine = Math.sin(rot*(Math.PI/180));
thisCosine = Math.cos(rot*(Math.PI/180));
xMove += pow*int(500 * thisCosine) / 100;
yMove += pow*int(500 * thisSine) / 100;
speed = Math.sqrt((xMove*xMove)+(yMove*yMove));
if (speed>max) {
xMove *= max/speed;
yMove *= max/speed;
}
} else {
xMove *= dec
yMove *= dec
}
if (_root.checkBound("car", _x + xMove, _y + yMove)) {
_x = _x + xMove;
_y = _y + yMove;
} else {
_x = _x - (xMove * 0.2);
_y = _y - (yMove * 0.2);
xMove = 0;
yMove = 0;
}
}

The bold area is where you need to insert your own collision detecting function... The one I used, uses three parameters. The first is the name of the movieClip, which helps state which boundaries affect the object. The second is the X coordinate being checked for collision, and the third is the corresponding Y coordinate.

I doubt that made any sense at all.


None

gasthatsmells

Reply To Post Reply & Quote

Posted at: 7/9/03 07:22 AM

gasthatsmells LIGHT LEVEL 11

Sign-Up: 12/30/02

Posts: 52

At 7/8/03 06:38 AM, AngryBinary wrote: That depends on the code you used to make the clip follow the mouse, really. First of all, you have to

Mouse.show();

or something to that effect...

Then, you either 'null;' the function you have set to make the clip follow the mouse (clip.customFollowMouseFunction = null;), and/or just remove the clip from the scene (clip.removeMovieClip();)

Thanks alot. All I did was put Mouse.show(); in the timeline actions and it worked lol. Thanks again.


None

Openwounds

Reply To Post Reply & Quote

Posted at: 7/9/03 06:13 PM

Openwounds EVIL LEVEL 14

Sign-Up: 12/14/02

Posts: 546

ok so this is a big ass topic and im not looking through all of it. What is the action script to switch images? like... in create-a-ride you click to change the spoiler and stuff. what is the script to do that?


None

ninjadeath

Reply To Post Reply & Quote

Posted at: 7/9/03 07:54 PM

ninjadeath NEUTRAL LEVEL 03

Sign-Up: 11/09/02

Posts: 16

At 7/9/03 06:13 PM, Openwounds wrote: ok so this is a big ass topic and im not looking through all of it. What is the action script to switch images? like... in create-a-ride you click to change the spoiler and stuff. what is the script to do that?

Simple:

tellTarget("spoiler") {
nextFrame();
}

I'm not sure if nextFrame() is the actual name of the function, but you get the idea.


Questioning

Elementsk8er506

Reply To Post Reply & Quote

Posted at: 7/9/03 08:20 PM

Elementsk8er506 NEUTRAL LEVEL 11

Sign-Up: 07/23/02

Posts: 117

does anyone know how to make walls in a game so you can't pass throu it but do stuff like jump on it or over it.

does anyone know how to make it so that once a movie clip gets to a certain point it could change scenes or something such as walking through a door. please help.

how do i make a movie clip do an action like shoot a lazor by pressing the "a" button or something? please help.


None

Openwounds

Reply To Post Reply & Quote

Posted at: 7/9/03 08:26 PM

Openwounds EVIL LEVEL 14

Sign-Up: 12/14/02

Posts: 546

At 7/9/03 07:54 PM, ninjadeath wrote:
At 7/9/03 06:13 PM, Openwounds wrote: ok so this is a big ass topic and im not looking through all of it. What is the action script to switch images? like... in create-a-ride you click to change the spoiler and stuff. what is the script to do that?
Simple:

tellTarget("spoiler") {
nextFrame();
}

I'm not sure if nextFrame() is the actual name of the function, but you get the idea.

uhm yeah sorta,but will that work if you have multiple things that can change? if i set that it wont be able to keep the other options the same would it


Questioning

TMP

Reply To Post Reply & Quote

Posted at: 7/10/03 12:56 AM

TMP LIGHT LEVEL 09

Sign-Up: 06/01/03

Posts: 164

Hey evilLudy, you think you could throw that AS for the inventory system into a quick fla for me to look at? If you could that would be great help.


Questioning

Elementsk8er506

Reply To Post Reply & Quote

Posted at: 7/10/03 01:59 AM

Elementsk8er506 NEUTRAL LEVEL 11

Sign-Up: 07/23/02

Posts: 117

this is miy 3rd or 4th time sending a post about this question because no one yet has answered.please some one help me.

how do u make walls? and also once a person pass through a certain point make it change scenes and also something like a person walking through a wall?


None

TMP

Reply To Post Reply & Quote

Posted at: 7/10/03 01:41 PM

TMP LIGHT LEVEL 09

Sign-Up: 06/01/03

Posts: 164

TheGrrrrrr81 wrote:

how do u make walls? and also once a person pass through a certain point make it change scenes and also something like a person walking through a wall?

onClipEvent (enterFrame) {
if (_root.guy, hittest(_root.wall)) {
[actions resulting from hit]
}
}

Thats simple for a guy hittest with a wall.


None

TMP

Reply To Post Reply & Quote

Posted at: 7/10/03 01:44 PM

TMP LIGHT LEVEL 09

Sign-Up: 06/01/03

Posts: 164

Forgot to say, where the actions are just make it like _root.guy._x -= 5 or some action for walls and changing scenes where you put actions just put a goto action.


None

alexsmolik

Reply To Post Reply & Quote

Posted at: 7/12/03 02:12 PM

alexsmolik LIGHT LEVEL 42

Sign-Up: 01/02/01

Posts: 8,613

I won't let this topic die ! It's so usefull !!!
eviLudy, I love you !

I play lottery. I always lose.
LOOK at my CAR VIDEOS on YouTUBE !!

BBS Signature

Questioning

NightCrawler64

Reply To Post Reply & Quote

Posted at: 7/12/03 04:24 PM

NightCrawler64 NEUTRAL LEVEL 01

Sign-Up: 07/12/03

Posts: 1

This may seem like a stupid question but...how do you add music to a movie...I've created one but i would like some music in it

Do you hav a actionscript for this???


Happy

StarCleaver

Reply To Post Reply & Quote

Posted at: 7/12/03 05:02 PM

StarCleaver LIGHT LEVEL 29

Sign-Up: 01/03/03

Posts: 10,102

At 7/12/03 04:24 PM, NightCrawler64 wrote: This may seem like a stupid question but...how do you add music to a movie...I've created one but i would like some music in it

Do you hav a actionscript for this???

you can use AS but it is not necessary. To add music to your movie just go to file-> import to library and then browse and find your music file. Then you'll find it in the library. You can drag it from the library or select the frame where you want the sound to be and open the property inspector. Select your music file and WALLAH! The music is added.

IF you need more information for all the sound options, go here:

http://www.angelfire.com/in4/star_cleaver/tut.html#section5

Hope that helps

-Star_Cleaver

I could surely die
If I only had some pie
Club-a-Club Club, son

BBS Signature

None

Anonymous1c4

Reply To Post Reply & Quote

Posted at: 7/12/03 11:55 PM

Anonymous1c4 LIGHT LEVEL 07

Sign-Up: 07/04/03

Posts: 469

How do you make a walking actionscript(when you press left or right he/she will move his/her legs and go to the left or right). Also i need a jump actionscript.


None

MahonenNiko

Reply To Post Reply & Quote

Posted at: 7/13/03 10:42 AM

MahonenNiko LIGHT LEVEL 06

Sign-Up: 04/05/03

Posts: 5

What is code for usual preloader???

I can't download the one from NG because I have Flas number 5.


Happy

StarCleaver

Reply To Post Reply & Quote

Posted at: 7/13/03 12:28 PM

StarCleaver LIGHT LEVEL 29

Sign-Up: 01/03/03

Posts: 10,102

At 7/12/03 11:55 PM, FusionGuy wrote: How do you make a walking actionscript(when you press left or right he/she will move his/her legs and go to the left or right). Also i need a jump actionscript.

That's alot top ask but i'll try to sum it up all nice for you.=)

The way i'm gonna show you how to do this will be a simple one where the guy will walk to the Left when you hit the left arrow and vice versa with the right. Its going to be the same animation for both walking left and right except it will be flipped over.

So anways, make your walking animation. If you want a good tutorial on walking animations you can see Percival's movies. He has a good one on the Walk Cycle. Okay, back to the topic. Make your walk animation and put it on an MC. Just copy all of the frames to an MC. You know what i mean i hope. Then on the first frame of your MC add a frame(F5) and make it a picture of the guy just standing there. then on the last frame of your walking animation put the actions:

gotoAndPlay(2);

this will make your animation "loop".

Then on the first frame of your MC put a stop(); action.

Now exit editing mode and place your MC on the main stage if it is not already there. Then put these actions on it:

onClipEvent (enterFrame) {
if (!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)) {
this.gotoAndStop(1);
}
if (Key.isDown(Key.LEFT)) {
this.play();
this._x -= 15;
this._xscale = 100;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this.play();
this._x += 15;
this._xscale = -100;
}
}

Now, see where it says "+=15" in both places? That's how far it will move when you hit the Left and Right arrow keys. Change those numbers to match your movements of your character. and that should be it. If that doesn't work tell me and i'll answer questions.

Now about the jumping script. Go look for a topic called "Look at This"(you might have to use the search bar) and on the first page there is a Jumping Script. That should help you.

Hope that Helps

-Star_Cleaver

I could surely die
If I only had some pie
Club-a-Club Club, son

BBS Signature

Happy

StarCleaver

Reply To Post Reply & Quote

Posted at: 7/13/03 12:34 PM

StarCleaver LIGHT LEVEL 29

Sign-Up: 01/03/03

Posts: 10,102

At 7/13/03 10:42 AM, mahonen wrote: What is code for usual preloader???

I can't download the one from NG because I have Flas number 5.

I thought the NG preloader was compatible with Flash 5? Does it give you an error or something? If not i guess you can use the

_framesloaded

and

_totalframes

methods. They would be something like this:

if (_framesloaded >= _totalframes) {
gotoAndPlay ("Scene 1", "start");
} else {
_root.loader._xscale = (_framesloaded/_totalframes)*100);
}

I just got that straight from the AS dictionary. I'm sure you can figure it out can't you? If not, tell me and i'll lend an extra hand.=)

I could surely die
If I only had some pie
Club-a-Club Club, son

BBS Signature

None

Inforcer

Reply To Post Reply & Quote

Posted at: 7/13/03 01:54 PM

Inforcer EVIL LEVEL 07

Sign-Up: 01/23/03

Posts: 40

At 7/13/03 12:34 PM, Star_Cleaver wrote:
At 7/13/03 10:42 AM, mahonen wrote: What is code for usual preloader???

I can't download the one from NG because I have Flas number 5.

Hum, thats wierd, I have flash 5 and the preloader works with mine. maybe its a new preloader. Anyway star_cleaver gave you enough script to make your own, :)


None

The-Mercenary

Reply To Post Reply & Quote

Posted at: 7/13/03 01:58 PM

The-Mercenary EVIL LEVEL 17

Sign-Up: 01/22/03

Posts: 2,620

Damn it, I posted with my bro's(inforcer) acount again.


None

coolazz0

Reply To Post Reply & Quote

Posted at: 7/13/03 05:26 PM

coolazz0 NEUTRAL LEVEL 03

Sign-Up: 07/25/02

Posts: 22

//Dumb
//But Easy "AI"
onClipEvent (enterFrame) {
dec = random(1000)+5;
}
onClipEvent (enterFrame) {
if (dec<=100) {
_x += 10;
}
if (dec >100 && dec<=400) {
_x -= 10;
}
if (dec >300 && dec<=500) {
_y += 10;
}
if (dec>500 && dec<=700) {
_y -= 10;
}
if (dec>700&& dec<=1000) {
_y -= 10;
}
}

Put that inside of a Mc


None

Anonymous1c4

Reply To Post Reply & Quote

Posted at: 7/13/03 11:19 PM

Anonymous1c4 LIGHT LEVEL 07

Sign-Up: 07/04/03

Posts: 469

At 7/13/03 12:28 PM, Star_Cleaver wrote:
At 7/12/03 11:55 PM, FusionGuy wrote:
That's alot top ask but i'll try to sum it up all nice for you.=)

Thanx alot it worked perfectly.


All times are Eastern Standard Time (GMT -5) | Current Time: 01:33 PM

<< Back

This topic is 286 pages long. [ 136 | 7 | 8 | 9 | 10148286 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!