AS3 - Small tips you're gonna need

Go down

AS3 - Small tips you're gonna need

Post  Glenn on Sat Jan 02, 2010 11:55 pm

AS3 - Small tips you're gonna need by Glenn

Here are some cool and really useful tips for ActionScript 3.0.



Variables:
Once when you are scripting, you need a value that can change so other functions can read this value when it's changed. That is why the variable is invented. It can be assigned as a lot of types, and the most common ones are these:
Code:
var example1:Number = 5.5;
var example2:int = 2;
var example3:String = "This is a string";
var example4:Boolean = false;
When you define a variable, you start with the word "var", followed by the name of the variable. After the name, you see what the variable is assigned as. It is followed by what the value or string is. Don't worry, the values of the variables can be changed easily.
When you assign a variable as a Number, it can carry numbers with a lot of decimals.
When you assign a variable as an integer, it carries numbers, but no decimals are allowed.
Strings; see the next tip.
Booleans are variables that can only hold two statements. "true" or "false". Very useful.
Code:
example1 = 3.7;
example2 = 6;
example3 = "This is how we change the values of variables!";
example4 = true;
To change the values of a variable, simply type the name of the variable, and just change the value! Math is allowed only on the right side. It can be made a bit more advanced, just read the "ActionScript 3.0 math" section.

What makes strings different:
There is one important thing you should know about what makes strings different. A string is a piece of text. When you write a piece of text, you need to put it inside "s to make Flash understand that any symbols used for scripting used in the piece of text is not to be used for it's functions. Just remember this.

ActionScript 3.0 math:
Let's use these example variables:
Code:
var mathExample1:Number = 0;
var mathExample2:Number = 3;
var mathExample3:Number = 5;
Let's say we want mathExample1 to be the equal to mathExample2 + mathExample3.
Code:
mathExample1 = mathExample2 + mathExample3;
Just as simple as that. Here's the rest:
Code:
mathExample1 = mathExample2 - mathExample3;
Code:
mathExample1 = mathExample2 * mathExample3;
Code:
mathExample1 = mathExample2 / mathExample3;
Now, let's say we want to add or remove something from the value, or divide it or multiply it. These are the codes you need:
Code:
mathExample1 += 2;
Code:
mathExample1 -= 2;
Code:
mathExample1 *= 2;
Code:
mathExample1 /= 2;
It's as simple as that.
If you need something to be calculated individually, add ('s like I did here:
Code:
mathExample1 = ((6 + mathExample2) * 4) / 2;
These can be added infinitely inside each other, but use only when needed!

If?
Oh yes, the "if" is one really important scripting item. You need something to happen only when a condition is true or not. This is a boolean variable that we are going to use in the if, followed by the if:
Code:
var trueOrNot:Boolean = true;

if (trueOrNot == true){
trueOrNot = false;
}
The if starts with the word "if", followed by the conditions Flash checks for. Always use two ='s when you write inside if's. It's just to make flash understand it's not only basic math, but something it checks for instead. Other math can be used in here. Then comes the clamps, and inside is where you put what you want to happen. There also is another option checking if something is NOT true:
Code:
if (!(someRandomVariable == 1)){

}
Just make a "!" in front of a (), with the conditions inside. This one checks if someRandomVariable is NOT 1. Here comes another smart function with the if:
Code:
if (someRandomVariable < 10){

}
If someRandomVariable is less than 10, then do what's inside the clamps.
Code:
if (someRandomVariable > 10){

}
If someRandomVariable is more than 10, then do what's inside the clamps.
You might also need two conditions to be true. No problem!
Code:
if (trueOrNot1 == true && trueOrNot2 == false){

}
Just add "&&" between the two and it will check both conditions. But what if you want Flash to do what's inside the clamps if only one of the conditions are true?
Code:
if (trueOrNot1 == true || trueOrNot2 == false){

}
Just add "||" between. NOTE: Those are not the letter "I", it is a symbol that is located on the left side of your keyboard.
Feel free to combine all of them and experiment, you can do alot!

The Trace function:
This function is one of the most useful in ActionScript 3.0. It gives you a message on the output window. You might not understand how this is useful now, but I'll explain.
Let's say you've made an "if" statement with lots other "if"s inside. But it doesn't work! Now you need to find the breakpoint of your script. Here's where the trace() function comes in. Write this in the outernmost clamp:
Code:
trace("What you'd like to be written in the output");
If this is printed in the output, this is not the breakpoint of your script. Now move the trace() into the next clamp. If it works here, this isn't the breakpoint either. Move it in until it doesn't print that in the output, and check for errors in whatever the trace() is inside.
This function also comes in handy when you have a function that you can't really make something happen with yet. Just to make sure it works.
It is also useable to trace values, like variables. You can put math inside.

Feel free to point out spelling and grammar mistakes, and also code mistakes (Which I highly doubt there are).
avatar
Glenn
Administrator
Administrator

Posts : 98
Join date : 2010-01-02
Age : 23
Location : Just here

View user profile http://justanotherpivotsite.roflforum.net

Back to top Go down

Re: AS3 - Small tips you're gonna need

Post  Pivetor on Mon May 17, 2010 3:32 pm

Pretty good, its thorough enough.
avatar
Pivetor
Administrator
Administrator

Posts : 72
Join date : 2010-05-17
Age : 24
Location : Virginia

View user profile http://www.Pivetworld.forumotion.com

Back to top Go down

Re: AS3 - Small tips you're gonna need

Post  munste on Fri Aug 13, 2010 11:02 am

what is actionscript?

_________________
COME ON we need more activity, get posting or i rape u.
avatar
munste
Administrator
Administrator

Posts : 71
Join date : 2010-08-13

View user profile

Back to top Go down

Re: AS3 - Small tips you're gonna need

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum