00:00
00:00
Newgrounds Background Image Theme

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

AS: sliding menus!

1,195 Views | 12 Replies
New Topic Respond to this Topic

AS: sliding menus! 2006-08-20 18:11:05


AS: main

Right then, this is my first tutorial I have ever wrote/written, so it may not be perfect.

What will this teach you?

Hopefully, after you have gone through this tutorial, you should know how to make a menu, that can slide out. Hopefully with a few variasion!

Ok then, lets start of setting up the flash and stuff.

first things first, make a new layyer and call AS, this is where any code that needs to go on the main time line will go, I advise you do this in all you animations/games.

for our menu, we will keep it simple, it will only make things apear and dissapre, by changing the alpha levels. so start by making a large rectangle that is of to the side of the stage, make it the of to the left. now press "f8" to turn it into a movie clip, and give it an instance name of "panel". just incase you dont know how to do this, there is a panel at the bottom of the screen for this.

Now in order to make use of the menu, we will need some buttons in it, so dubble click it to open it up, everything else should 'tint'. Make two circles, one red and one green. convert these both to 'buttons' by pressing "f8". give the green button a instance name of "notinvisible" and the read an instance name of "invisible".

Back to the main stage. Make another square, convert it to a mocie clip and give it an instance name of "square". finale, make a circle, convert it to a 'button' and give it an instance name of "button".

right then, now for the code.

due to lack of space, I will have to give you the code, and explain it as i go along. I would of built the code up as i went along, thus making sure you can see where the code comes from.

click on the first frame of the AS layer, press "f9" to bring up the actipn script panel, and copy and past this code in.

_root.onLoad = function() { // do this code when the movie loads
menumove = 0; // sets the movement of teh menu
maxout = 40; // set the furthest out the panel should go
maxin = 40; // set the furthest in teh panel should go
};
_root.button.onPress = function() { // do this code when you press the button
if (menumove == 5 || _root.menu._x == maxout) { // do this code if the menu id moveing right or (||) is fully right
menumove = -5; // sets the menus movement so that it will go left
} else { // do this if the menu is not moveing right or fully right
menumove = 5; // set it so that the menu moves right
}
};
_root.panel.invisible.onPress = function() { // do this code when you press the invsible button
_root.square._alpha = 0; // make the square so that you cant see it
menumove = -5; // set the menu to move back in
};
_root.panel.notinvisible.onPress = function() { // do this code when you press the visible button
_root.square._alpha = 100; // set the square so that you can see it
menumove = -5; // set teh menu to move back in
};
_root.onEnterFrame = function() { // do this code every frame
if (menumove != 0) { // if the menu is not ment to be staying still
_root.panel._x += menumove; // add the value of the movement to it
if (_root.panel._x<-maxin) { // if it is to far right
_root.panel._x = -maxin; // move the panel to the right postion
menumove = 0; // stop the panel moveing
} else if (_root.panel._x>maxout) {
_root.panel._x = maxout; // move the panel to the right postion
menumove = 0; // stop the panel moveing
}
}
};

hopefully you should understand from the comments i put in how that code works! you may find that you will have to change some of the values to suit your needs, such as how far out the panel needs to move, or how fast.

as you can see, it is very simple, but very effective. you may find it more practicle though, to have the code on the buttons and manus, it depends how you like to have your code set out.

so what do you lot think of my first tutorial?

Response to AS: sliding menus! 2006-08-20 18:16:47


"points for originality but... i doubt it'l actually work."

lol just kidding im sure it works.
good job!


OS: Ace, coming soon to Newgrounds. Keep an eye out for it.

BBS Signature

Response to AS: sliding menus! 2006-08-20 18:22:19


actually, it dose work, i made it my self as i was writing this tutrial, and copy and pasted the code right out of flash.

if it dont work, i either told you enter the wrong instance name, you did somthing wrong or it buggered up by some evil pixies.

Response to AS: sliding menus! 2006-08-20 18:24:34


Example?


BBS Signature

Response to AS: sliding menus! 2006-08-20 18:26:04


At 8/20/06 06:16 PM, Elementrat wrote: "points for originality but... i doubt it'l actually work."

lol just kidding im sure it works.
good job!

lmfao

But yeah an example would do.
And I guess the same shit is already under AS:Main.

Response to AS: sliding menus! 2006-08-20 18:26:18


At 8/20/06 06:24 PM, -DonutMaster- wrote: Example?

erm... what do you mean? I aint going to upload this! but if you want me two email it sure.

it takes what... 2 minutes to make this your self, try it and take a look.

Response to AS: sliding menus! 2006-08-21 06:49:24


here is an example of it in action

and i have changed the code a little, small bug fix

_root.onEnterFrame = function() { // do this code every frame
if (menumove != 0) { // if the menu is not ment to be staying still
_root.panel._x += menumove; // add the value of the movement to it
}
if (_root.panel._x<maxin) { // if it is to far right
_root.panel._x = maxin; // move the panel to the right postion
menumove = 0; // stop the panel moveing
} else if (_root.panel._x>maxout) {
_root.panel._x = maxout; // move the panel to the right postion
menumove = 0; // stop the panel moveing
}
};

that needs to relace the onEnterframe function in the original.... sorry about that

Response to AS: sliding menus! 2006-08-22 09:40:39


At 8/21/06 06:49 AM, thecoshman wrote: here is an example of it in action

and i have changed the code a little, small bug fix

_root.onEnterFrame = function() { // do this code every frame
if (menumove != 0) { // if the menu is not ment to be staying still
_root.panel._x += menumove; // add the value of the movement to it
}
if (_root.panel._x<maxin) { // if it is to far right
_root.panel._x = maxin; // move the panel to the right postion
menumove = 0; // stop the panel moveing
} else if (_root.panel._x>maxout) {
_root.panel._x = maxout; // move the panel to the right postion
menumove = 0; // stop the panel moveing
}
};

that needs to relace the onEnterframe function in the original.... sorry about that

ummm.. The flash in that link didn't do anything.. õ_õ There were two green shapes and one of them was like a button and i tried clicking and draging both but nothing happend.. Fail.

Response to AS: sliding menus! 2006-08-25 17:11:00


At 8/22/06 09:40 AM, seel wrote:
ummm.. The flash in that link didn't do anything.. õ_õ There were two green shapes and one of them was like a button and i tried clicking and draging both but nothing happend.. Fail.

yer, the circle one is a button, you just need to click it. it should work, did when i tested it, very strange... in that case i will have to go over all of this to make sure...

Response to AS: sliding menus! 2006-08-25 17:34:11


At 8/22/06 09:40 AM, seel wrote: ummm.. The flash in that link didn't do anything.. õ_õ There were two green shapes and one of them was like a button and i tried clicking and draging both but nothing happend.. Fail.

Shut the Fuck up. It did work, quit being such an ass.

Response to AS: sliding menus! 2006-08-26 13:02:05


ok, so the example is a bit broken. the only thing wrong with teh example, is that the button that brings menu in, wont put it back again. if any one else says anything else is wrong, they should go shut up! but as for the code, I can't help but notice that you are all comenting on how the example dont work, but havent seemed to of tried it your self?

just seems a bit rude to comment when you are in no position to.

and 'it dont work' dont count as constructive!

Response to AS: sliding menus! 2006-08-26 13:04:42


At 8/25/06 05:35 PM, NoEscapeFromReality wrote: Erm, sorry to break it to you, but the example doesn;t work.

It did for me. It just sucked :s I'm sure that wasn't more than five lines of code, tops.


BBS Signature

Response to AS: sliding menus! 2006-08-27 06:29:46


At 8/26/06 01:04 PM, Brother_Paranoia wrote:
It did for me. It just sucked :s I'm sure that wasn't more than five lines of code, tops.

no need to be a party pooper! sure that example looks shit, is is just to show what it is doing. and if you can get that to work with only five lines of code i will buy you a house!

I use this code, with minour adaptions, on more or less everything, it is a solid bit of code. just the menu has realy pointless buttons on it.