Useful Codes with tuts and fla's

**[color=red]Sorry, i have not yet found all my FLA’s, i’ll put them up soon[/color]

[center]MC’s As Buttons[/center]
[center][FLA] || [Preview][/center]

1
Draw a Picture.

2
Select it and press F8 and make sure Button is checked.

3
Double click it and insert keyframes under the Up, Over, Down, Hit.

Up is the button whenever the pointer is not over the button.
**Over **is representing the button’s appearance when the pointer is over the button.
Down is representing the button’s appearance as it is clicked.
Hit is defining the area that responds to the mouse click. This area is invisible in the SWF file.

4
Once it is a button and you have all the states add in;

 
on (release){
//action
}

For E.G.:

 
on (release){
**[color=red]gotoAndPlay("6");[/color]**
}
[color=green]//this will go to and play frame 6[/color]

 
on (release){
[color=red]**gotoAndPlay("part 2");**[/color]
}
[color=green]//this will go to and play frame named part2[/color]

[center]Set Timer, By Using A Button[/center]
[center][[FLA] || **[url=“http://www.kirupa.com/forum/attachment.php?attachmentid=11259”]Preview**][/center]

1
To frame 1, or whatever frame the button is in, add in this code;

 
_root.**notime** = 0; //this is a variable the code i made uses to make sure the timer only sets when it is not already counting down

2
OK, in this code i have just used a movie clip to act as a button, but you can use a button. Add this code to your button;

 
[color=red]**on (rollOver) {**
**this.gotoAndPlay(2);**[/color] //this just plays the rollover frame of my movie clip, if you have a button **delete the code in red**
[color=red]**}**
**on (rollOut) {**
**this.gotoAndPlay(21);**[color=#000000] //this just plays the rollout frame of my movie clip, if you have a button **delete the code in red**[/color]
**}**[/color]
on (release) {
if (_root.**notime**>=1) { //checks to see if the variable notime is 1
_root.text.gotoAndPlay(); // if it is 1, then it will not start the timer again
} else if (_root.**notime**<=0) {//checks to see if the variable notime is 0
_root.text.gotoAndPlay(2); // if it is 0, then it will start the timer
}
}
 

3
Make a symbol with the **instance name **of text. In it, put a dynamic text box named display. After you have put in the text box put in another keyframe at frame 2.

[color=red]NOTE [/color][color=black]if you want it invisible set the alpha of this movie clip to 0.[/color]**

4
In frame 1 of the symbol put in this code;


stop();
_root.text.display = 45; //Sets the timer variable to 45, just looks good if it is visible. Make this the same as the actual timer.

5
In **frame 2 **of the symbol put in this code;

 
_root.**notime** = 1; //Make the button invalid until the timer makes it valid again
var numTimeLimit = **45000**; // This sets the timer. 1 sec = 1000, so this is for 45 seconds
var bolFirstTime = true;
function countDownF() {
		if (bolFirstTime) {
				numTimeStart = getTimer();
				bolFirstTime = false;
		}
 
		numTimePassed = getTimer() - numTimeStart;
		display = Math.round((numTimeLimit - numTimePassed)/1000);
		if (numTimePassed > numTimeLimit) { // If the timer is finished
				_root.**notime** = 0; //Set ***notime*** to 0, so the button will work again!.
				**[color=seagreen]gotoAndPlay(1);[/color]** //Goes back to frame one of this symbol also so the button will work properly or, alternatavely, you can leave out the code in green so they have to double click the button for it to work .
				 //Put in any of your own actions here.
	clearInterval(countDownI); // clear the interval
}
}
countDownI = setInterval(countDownF, 50);
stop();

[center]Mouse Out/Mouse Over Using MC’s[/center]
[center][FLA] || [Preview][/center]

1
Create a movie clip.
2
Insert 6 keyframes for example, frames 1, 2, 20, 21, 40, 41.

3
On 4 of the keyframes, for example, frames 1, 20, 40, 41, on each of these keyframes put in;

 
stop();

4
Put your idle picture on frame 1, and your rollOver animations on keyframe 2 - 20, [color=red]for this example[/color].

5
Put your rollOut animations on the keyframe 21 - 40, [color=red]for this example[/color].

6
Put your pressed animations on the keyframe 41, [color=red]for this example[/color].

7
Go back to scene 1 and put this code on your movieclip;

 
on (rollOver) { 
this.gotoAndPlay(**"roll in scene"**); //goto And Play from roll in scene of this MC
}
on (rollOut) {
this.gotoAndPlay("**rollout scene**");//goto And Play from rollout scene of this MC
}
on (press) {
this.gotoAndPlay("**pressed scene**");//goto And Play from pressed scene of this MC
}
on (release) {
this.gotoAndPlay(**"idle"**);");//goto And Play the idle scene of this MC
}
 

[center]Make Button Text Fade In/Out[/center]
[center][color=#ff0000]Updates have been made, no more Freezing up on load, and if you download the fla, remove the code from frame 1![/color][/center]
[center][[FLA] || **[url=“http://www.kirupa.com/forum/attachment.php?attachmentid=11567&stc=1”]Preview**][/center]

OK, so try putting the text as a movie clip(f8):slight_smile: and then add

-1: To the Frame add;


//you no longer need a code here

-2: To The Button(we’ll call ButtonA) add;


on (rollOver) { //checks if the mouse is over
_root.pizza = 1; //sets the variable, called pizza to 1
_root.meh= 0; //sets the variable, called meh to 0
}

-3: Insert the text and make it a movieclip, name it text, in the properties menu. [color=red]Make sure it is the instance name and not the symbol name.[/color]

-4: Make the alpha of the movie clip 0%

-5: To the movie clip add; [color=#ff0000]Fixed[/color]


 
onClipEvent (enterFrame) {
if (_root.pizza == 0) {
_root.text._alpha -= 10;
_root.meh=1;
}
if (_root.text._alpha<=0) {
_root.text._alpha -= 0;
}
if (_root.text._alpha>=100) {
_root.text._alpha += 0;
}
if (_root.pizza == 1) {
_root.text._alpha += 10;
}
}
 
 
 

-6: To The Next Button(we’ll call ButtonB) add;


on (rollOver) { //checks if the mouse is over
_root.pizza = 0; //sets the variable, called pizza to 0
_root.meh= 1; //sets the variable, called meh to 1
}

-7:** Insert the next text and make it a movieclip, name it text2, in the properties menu. [color=red]Yet again, make [/color][color=red]sure it is the instance name and not the symbol name.[/color]**

-[color=black]8[/color]: Make the alpha of the movie clip 0%

-9: To the movie clip add; [color=red]Fixed[/color]


 
onClipEvent (enterFrame) {
if (_root.meh == 0) {
_root.text2._alpha -= 10;
_root.pizza = 1;
}
if (_root.text2._alpha<=0) {
_root.text2._alpha -= 0;
}
if (_root.meh == 1) {
_root.text2._alpha += 10;
}
if (_root.text2._alpha>=100) {
_root.text2._alpha += 0;
}
}
 
 
 

[color=red]**NOTE: **[/color][color=black]If you want to make it go to a certain frame put in this code, on the button in this code it will go to and play 3;[/color]


**on (rollOver) { //checks if the mouse is over**
**_root.pizza = 0; //sets the variable, called pizza to 0**
**_root.meh= 1; //sets the variable, called meh to 1**
**}**
**[color=red][u]OR, depending on the button[/u][/color]**
**on (rollOver) { //checks if the mouse is over**
**_root.pizza = 1; //sets the variable, called pizza to 1**
**_root.meh= 0; //sets the variable, called meh to 0**
**}**
 
on (release) { //checks if the mouse is released
gotoAndPlay(3);
}

And the new code for the frame will be;


_root.pizza = 0; //sets the variable, called pizza to 0
_root.meh = 0; //sets the variable, called meh to 0
stop(); //just stops the frame from playing

And if you wanted it do go on mouse out i would be;


**on (rollOver) { //checks if the mouse is over**
**_root.pizza = 0; //sets the variable, called pizza to 0**
**_root.meh= 1; //sets the variable, called meh to 1**
**}**
**[color=red][u]OR, depending on the button[/u][/color]**
**on (rollOver) { //checks if the mouse is over**
**_root.pizza = 1; //sets the variable, called pizza to 1**
**_root.meh= 0; //sets the variable, called meh to 0**
**}**
 
on (rollOut) { //checks if the mouse is out
_root.pizza = 0; //sets the variable, called pizza to 0
_root.meh= 0; //sets the variable, called meh to 0
}
on (release) { //checks if the mouse is released
gotoAndPlay(3);
}