FlashPitt 09 - Intermediate ActionScript 3.0 Anatomy of ...

cabbagetreatmentΛογισμικό & κατασκευή λογ/κού

4 Ιουλ 2012 (πριν από 4 χρόνια και 11 μήνες)

279 εμφανίσεις

}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Anatomy of ActionScript
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Anatomy of ActionScript
Anatomy of ActionScript
Vocabulary
Read the ActionScript Diagram
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Vocabulary
Variables
DataTyping
Tracing
Functions
Scope
Event Handlers
Objects and Classes
Methods
Properties
Comments
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Variables
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Variables
St or age cont ai ner
var
myName:
String  “Josh”;
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
DataTyping
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Data Typing
Associ at es a var i abl e wi t h a t ype of val ue
var myName
:String
 “Josh”;
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Tracing
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Tracing
trace(“hello”) //outputs the string hello
var name:String = “Josh”;
trace(name) //outputs the string Josh
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Tracing
trace(“hello”)
//outputs the string hello
var name:String = “Josh”;
trace(name)
//outputs the string Josh
Outputs to a
window only
the developer
can see.
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Functions
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Functions
function onClick(){
play();
}
onClick();
Declares the Function
Calls the Function
Groups of reusabl e code
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Functions
function onClick(){
play();
}
onClick();
Declares the Function
Calls the Function
Groups of reusabl e code
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Functions
function onClick(){
play();
}
onClick();
Declares the Function
Calls the Function
Groups of reusabl e code
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Arguments
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Arguments
mc.gotoAndPlay(
“in”
);
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Arguments
mc.gotoAndPlay(
“in”
);
Declares option
for the function.
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
Accessibility of functions, values,
and objects through code
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
function getMyName(){
var myName:String  “Josh”;
trace(
myAge
);
}
function getMyAge(){
var myAge:Number  29
trace(
myName
);
}
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
function getMyName(){
var myName:String  “Josh”;
trace(
myAge
);
}
function getMyAge(){
var myAge:Number  29
trace(
myName
);
}
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
function getMyName(){
var myName:String  “Josh”;
trace(
myAge
);
}
function getMyAge(){
var myAge:Number  29
trace(
myName
);
}
Neither value is is accessible
myName Scope
myAge Scope
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
function getMyName(){
trace(
myAge
);
}
function getMyAge(){
trace(myName);
}
Now the Values Are OK
var myName:String  “Josh”;
var myAge:Number  29
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Scope
function getMyName(){
trace(
myAge
);
}
function getMyAge(){
trace(myName);
}
The New Scope
var myName:String  “Josh”;
var myAge:Number  29
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Event Handlers
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Event Handlers
mc.addEventListener(MouseEvent.CLICK, onClick);
This Registers all CLICKs on mc to fire off
the onClick function
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Objects and
Classes
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Objects and Classes
Objects are instances manipulated
Programatically
Classes are blueprints / templates that can be
reused over and over with minor adjustments
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Methods
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Methods
A function or command associated with an
object
play() is a method of MovieClip
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Properties
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Properties
An attribute that can be read and/or set.
For example height, width, or alpha of an object.
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Comments
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Comments
// used for making notes in the code
/* They can be life savors
especially in larger projects
or when working with
multiple developers */
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Anatomy of
ActionScript
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Anatomy
code blocks {}
dot syntax .
semi colons ;
parenthesis ()
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Code Blocks
function onClick() {
mc.gotoAndPlay(“in”);
navLoc= “main”;
}
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Code Blocks
function onClick() {
mc.gotoAndPlay(“in”);
navLoc= “main”;
}
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Code Blocks
function onClick() {
mc.gotoAndPlay(“in”);
navLoc= “main”;
}
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Code Blocks
function onClick() {
mc.gotoAndPlay(“in”);
navLoc= “main”;
}
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Dot Syntax
mc
.
gotoAndPlay(“in”);
separates an object
and a method
or used as targeting
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Semi Colons
mc.gotoAndPlay(“in”)
;
End of a line
of code
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Parenthesis
mc.gotoAndPlay
(“in”)
;
An Argument
that specifies
what to do
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Read the AS
Diagram
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Reading the AS Diagram
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Reading the AS Diagram
property
Note the colon.
That’s an indication
of a property
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Reading the AS Diagram
data type
The data type
describes the
value required by
the property
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Reading the AS Diagram
Method
Note the
parenthesis. That’s
an indication of
a method
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Pop Quiz
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Name a Method
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Name a Method
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Name a Property
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Name a Property
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Anatomy
code blocks {}
dot syntax .
semi colons ;
parenthesis ()
}
Fl ashPi t t 09 - I nt er medi at e Act i onScr i pt 3.0
Vocabulary
Variables
DataTyping
Functions
Scope
Event Handlers
Objects and Classes
Methods
Properties
Comments