PDA

View Full Version : interactivity for idiots


Alias13
01-02-2006, 11:01 PM
interactivity for idiots
a tutorial by alias13

1. buttons: there are lots of buttons tuts out there already. this is an advanced one. to make a button, you convert something to a symbol, then chose button. then change the 4 button frames to whatever you want them to be. if you cant follow this, go find a different tut. heres the button we have so far.

http://i2.photobucket.com/albums/y30/Alias13/button.swf

now lets try making an animated button like this.

http://i2.photobucket.com/albums/y30/Alias13/uberbutton.swf

that sort of button is very easy to make. you just have to put a movie clip of the spinning dots in the up button frame. then flip the movie clip for the down frame. then make another movie clip for the down frame.

heres a random but useful fact. you can make a movie clip work like a button with the code

onClipEvent(enterframe){
this.onRollOver = function(){
gotoAndStop(2)
}

this also works with onPress, onRelease, onRollOut, and onReleaseOutside.

2. drop down menu.

i had no idea how to do this before, but i figured it out caues i wanted to write a tut about it. heres what we're shooting for.

http://i2.photobucket.com/albums/y30/Alias13/menu.swf

now to start make a movie clip called button, and write menu on it.
then put two frames in it.
in the second frame, put whatever animation you want the button drop down to be in a movie clip.

now go back the your movie clip/button. to make it work properly give it the following code.

onClipEvent(enterframe){
this.onRollover = function(){
this.gotoAndStop(2)
}
this.onRollout = function(){
this.gotoAndStop(1)
}
this.onReleaseOutside = function(){
this.gotoAndStop(1)
}
}

then make a second frame in your main timeline. in it put how you want your menu to look once its finished, complete with buttons and everything. now go back into your movie clip/button, and, in the last frame of your menu animation, put the code

_root.gotoAndStop(2)

now go back your main timeline, and in that second frame, make a fill that goes around everything that is in your menu. your menu will disapear when it touches this fill. make the fill a button and give it this code.

on(rollOver){
_root.gotoAndStop(1)
}

then change its alpha to zero to make it invisible, and your done.

3. custom cursors:
this is incredibly simple. just make any arrow that points up and to the left. then make it a movie clip and give it the code

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

thats so easy i dont really think you need an example. plus i dont want to make one.

4. custor cursors advanced:
whats that you say? you don't want your cursor to be an arrow pointing up and to the left. ok, whatever. the reason the up and to the left arrow works is because flash automatically makes the center of a new movie clip its top left corner. if you want to make any other shape, you'll have to edit the movie clip so that the little white cross is whereever you want your mouse tip to be. when you enter the code i gave you, the tip of your mouse will align with the center of that little white cross.

5. animated cursors:
now for the fun part; animated cursors. lets say you want to make a shooting game or somthing, so you want your cursor to do somthing when you click. well, thats easy. start by making your cursor movie clip animated. add a bunch of frames to the end of your movie clip, and don't forget to put a stop() script on the first frame. now we need to make your cursor work like a button, so use this code.

//you don't need to add an onClipEvent(enterframe){ handler because you already have one.
this.onMouseDown = function(){
this.play()
}

there. now it will play though the animation after you click the mouse.

5. preloaders

ok, first the really simple way. if you made a short anim and dont want to put much effort into the preloader, just do this. start by making a rectagle with an outline. now convert just the rectangle(not the outline) into a movie clip. then give it this code

onClipEvent(enterFrame){
this._xscale = (_root.getBytesLoaded()/_root.getBytesTotal())*100
if (this._xscale == 100){
_root.play()
}
}

6. advanced preloaders:

now the idea behind this is that we make a hundred frame animation, then give it the code

onClipEvent(enterframe){
this.gotoAndStop((_root.getBytesLoaded()/_root.getBytesTotal())*100)
}

to make it go the the frame the represents the % of the movie that is loaded. you can also use _root.framesLoaded, but this makes for a jerky preloader.
now to make a hundred frame animation, your going to want to use tweening. what i do is change the corner rounding on the rectangle tool to about 20(double click on it to change this), and use it to draw a bar. then change the bar into a movie clip. once inside the movie clip, select the bar, but not its outline, and right click and chose distribute to layers. now put a mask on the layer. change the corner rounding back to zero, and draw a rectangle slightly bigger than the preloader one. put it right next to the preloader bar. now make a new keyframe on frame 99 and move the mask bar so it just barely covers the preloader bar. now make it tween. now on the last frame put a button that says 'play', and give it the code

on(release){
_root.play()
}


now put the code i showed you above in the movie clip itself, and your done.
if you want the preloader to show the percent of the movie thats loaded, just add a new layer to your preloader clip, and put a block of dynamic text in it. make the variable for the dynamic text "text"(without the quotes, and the variable can be changed in the propertys bar.) now put this code in the first frame of your movie clip.

text = Math.round((_root.getBytesLoaded()/_root.getBytesTotal())*100)

and that should work

7. code you should know:

here is some simple code that you should have memerized if you want to be good at actionscripting.
first, the handlers. handlers are only neccisary in movieclips and buttons, and they tell flash when to do what you tell it to do.
for movieclips, the handlers all begin with onClipEvent(. once you type that in, a list should pop up with all kind of things to put in the brackets. the most commons ones are:

enterFrame: this is the handler for most movieclip functions. this will make the included code happen every frame. even if the movie is stoped, it will still redo the code as if it was running.

load: this handler will make the code happen only once, when the movieclip first appears in the movie. i've used this for making the mouse disappear with a custom cursor.

there are others, but i've never used them.

if your working with buttons, your handlers will all start with on(. once again, this will make a list pop up. here are some common ones.

release: the code will execute when you release the button. use this for most buttons.

press: when you press the button.

rollOver: when you rollover the button.

you get the idea. some other ones are rollOut, releaseOutside, and mouseDown.

functions are what you put in the handlers, they make stuff happen in your code. some very common and useful ones are:
play(): play the current movie. if put in a button, it will target _parent. in a movieclip, it will target the movieclip itself. don't forget the brackets or it won't work.
gotoAndPlay(): same as play, but you put a frame number in the brackets, and it will play starting from that frame. or to pick a scene, this is the format
gotoAndPlay("scene name",frame number)
gotoAndStop(): guess what this does.
stop(): if you put this in a frame, the movie will stop when it gets to that frame. very useful. otherwise, works the same as play, only it stops the movie.

targets: you will see i used the words _root and _parent. these are targets. they determine what movieclip will be affected by a function.

_root: you will be useing this alot. targets the main timeline. to target a movieclip or button on the main timeline, use _root.yourmovieclipsname.
eg:

on(release){
_root.movieclip.gotoAndPlay(5)
}

will make the clip called movieclip go to it's 5th frame and play.

_parent: this targets the movieclip which the current clip is in. do not use this to target _root, even if your clip is on the main timeling. thats just ugly.

this: this(lol) targets the current movieclip itself. has all kinds of uses.

and now you have a very basic knoledge of coding.


note: all of the code in this tut should work if copied directly into flash, but i didn't actually test any of it, so if you find an error, please tell me.

note: if your animation just plays though without you clicking the button, you probably need to put the action stop() in the first frame. please do so before posting in the thread.

Alias13
01-03-2006, 11:19 AM
ohh double post. added advanced custom cursors stuff and animated cursors stuff. i might add screenshots if i get bored sometime.

Lambi
01-04-2006, 07:10 AM
10/10 I think it covers everything you need to know aout button's :)

Sword-Man
01-04-2006, 08:03 AM
This is excellent, why not make "Movieclips for morons?"

sticktastic#3
01-04-2006, 08:42 AM
for teh animated button do you add a motion guide :confused:

ive tried makin it a movie clip and nothings happening.. i know im doing summa wrong.. just dont know what 8-)

Alias13
01-04-2006, 09:06 PM
to make a movieclip a button, instead of using the code

on(________){
}

use

this.on________ = function(){
}

and replace the blank with release or whatever you want it to do.

i find motion guides and tweening is more trouble than its worth... but thats just me. i might make tuts on other stuff if i felt like it.

edit: do you guys think this should be in the official tutorials? some mod come decide.

Alias13
01-05-2006, 10:31 AM
updated. added basic preloader stuff.

edit: added advanced preloader stuff

Kam!kaz3
01-06-2006, 09:01 AM
i got a weird thing what i dun know to get rid off heres a pic, and link if it doesnt work :
http://i28.photobucket.com/albums/c232/Kam1kaz34/naamloos.jpg

http://i28.photobucket.com/albums/c232/Kam1kaz34/naamloos.jpg


thnx for reading/trying to help, Kam!kaz3

bamaboy
01-06-2006, 02:56 PM
nice tute and the reason you get that, is cuz you need to convert it to a button(or movieclip) and then click it....then you should be able to apply actions to it...and read the tute again...

Kam!kaz3
01-07-2006, 03:38 AM
but i already did that... i guess... ill take a look again... double click or only 1 click ?

Alias13
01-07-2006, 12:25 PM
one click.

Alias13
01-08-2006, 01:05 PM
added the 'code you should know' section.

what do i have to do to get this into the macromedia flash tuts section?

KiLLeR404
01-08-2006, 07:08 PM
Tell a mod (i think they can)

Alias13
01-10-2006, 05:23 PM
paperclip, cn you move this to the official tuts?

Paperclip
01-10-2006, 07:36 PM
Done and done....

Alias13
01-10-2006, 08:55 PM
mucho gracious. (spanish... i feal so smart)

Kam!kaz3
01-11-2006, 08:21 AM
Yay! it works this goes to my favorites thingy :D finally after al those dumb actions of me it works :) (soz for the ridiculous post, i just had to)

mathiasno4
01-15-2006, 04:15 AM
my drop down menu does still not work. make some pics. cause it's how to understand the tut.

Xyo
01-16-2006, 05:22 PM
When I make the loadbar thing...nothing happens, it just shows a red bar flash then my animation???

Alias13
01-16-2006, 05:29 PM
you forgot to put stop() in the first frame of your anim. happens all the time.

zmobie
01-23-2006, 12:57 PM
Very nice tutorial.

I'm going to try that drop-down menu thing later today. I tried to do it from some other tuts and it didn't work.

I knew most of the basics, but this was some good stuff. A lot like Polnareff's AS guide.


Also, isn't mouseDown usually used for movieclips? I've only seen used for MCs, but I could be wrong.

Alias13
01-23-2006, 01:32 PM
well yah, mouseDown also works on buttons, but it's only nessisary for complicated stuff, and if your doing complicated stuff, your probably using mc's.

thanks for the positive feedback. there's probably a better way to make dropdown menus, but i made that one by scratch.

Maelstrom
01-23-2006, 02:55 PM
How do I make an interactive sig, like yours?

Alias13
01-23-2006, 04:13 PM
make a sig in flash, make buttons that link between the frames.

Maelstrom
01-23-2006, 05:12 PM
Hmm... It didn't work...


I made the button, and I put in the code you gave. I made a frame in frame 5, which opens something else up. I went back to the code, and changed "enterframe" to "5". But it shows an animation of the first frame with the button, and the 5th frame... And it says there are 6 actionscript errors....

zmobie
01-25-2006, 12:14 AM
I think you may be missing a stop() action on the first frame.

Just write stop() in the first frame's AS box.

Alias13
02-02-2006, 07:53 AM
actually go back and check your script. i added 'put stop in the first frame' in big red bold italic letters, so that should help some people :)

sixstrings777
04-07-2006, 07:23 AM
Nice, tut! This goes in my favorites. Favorites>>Add...>>Awesome Tutorial>>OK

sixstrings777
04-10-2006, 01:00 AM
Oh, when I made a cursor, the mouse isn't hidden. How do I fix that?