Page 1 of 1

Need coding advice

PostPosted: Sat Dec 08, 2012 11:43 pm
by Mr D
First: I am sorry I am posting an request here but I didnt find out how to do it online and was not able to figure it out from .fla files that have that code. And I know that a lot of people here know how to do that.

Ok here is what I need to know (btw using AS2). I want to be able to change costumes with one button click. So for example I want that on press of the button for it to change frames from 1 to 2 or 3 in symbols named Helmet,Body,legs. If someone is so nice to explain it to me step by step and so I can understand how it actually works and see why it works like that.

thanks

Re: Need coding advice

PostPosted: Sun Dec 09, 2012 3:26 am
by Thaedael
Brought this to KatsuO_O's attention, I know he has done it before in animations for me so hopefully he will be able to help you!

Re: Need coding advice

PostPosted: Sun Dec 09, 2012 3:43 am
by KaTsuO_O
First of all you need to give your movieclips instance names, it is the name that the program will use to communicate with the movieclips. It is not the same thing as the name you give it when you create it, if you click on a symbol and then open properties you'll see where you can enter an instance name. you can write what ever you want, but it is recommended to keep it simple so that you can remember it.

Let's say we start with the Helmet, give it the instance name helmet. If the helmet is inside a head symbol then you need to give the head an instance name as well, which should be head. Same if the head is inside a character movieclip.

Then for the different helmets, make keyframes inside the helmet movieclip, add one on each frame and put the "stop();" action on all of them.

The code for the button is basically:

on (release) {
helmet.play();
}

It means that when you release it will play the frames inside the helmet, however since you got stop(); on each it will stop on the next one and loop back to the first frame again.

but if the helmet is inside a head movieclip then you need to change it to:

head.helmet.play();

if the head is inside a character movieclip then you need to change it to:

character.head.helmet.play();

So it gives the path for the program to follow.

If it still doesn't work then that should be because the button is not in the root of the file. It would just be confusing to explain so I can just say, add _root. before helmet.play(); or how you chose to structure it.

Re: Need coding advice

PostPosted: Sun Dec 09, 2012 4:02 am
by Mr D
Thanks KaTsu it works great. I was even able to figure out how to make go to specific frame inside the symbol. Thank you time million :D

Re: Need coding advice

PostPosted: Sun Dec 09, 2012 4:17 am
by Thaedael
Another case solved by KatsuO_O furry coder extra-ordinaire! Going to move this to the tutorial section I think and keep it pinned in there <3

Re: Need coding advice

PostPosted: Sun Dec 09, 2012 12:13 pm
by OwnerOfSuccuby
By the way - you can read 1a and 1b and 1d about it there ;)
viewtopic.php?f=29&t=2370

You may need to work with global variables too some times if you will need to make the game and you already need to change components animation.

Re: Need coding advice

PostPosted: Thu Dec 13, 2012 12:49 pm
by GoRepeat
Word of advice: set a variable then use gotoAndStop instead. For some reason, I have no idea why, flash will start to lag to hell with too many Play commands (even if they are followed by a stop). On the base level of your animation put in:

Var myVar: Number = 1

Then just use that number to represent the sub frame for armor you want to display across the character. (Like 1 = nude, 2 = gentleman's mustache, etc).
ex:

myMovieClip.gotoAndStop(_root.myVar)