SlideShare a Scribd company logo
Introducing to AS3 Programming
ENGR. SOLIEL G. MUTYA
DLS-CSB
MAY 2016
ACTIONSCRIPT 3.0 DATA TYPES
• AS3 is a structured language as well as an
object-oriented language.
• It is a structured because it is built around
functions.
• It is an OOP because it is built around classes
and objects. Data identified for I-P-O will need
to be stored as data objects.
AS3 DATA TYPES
• Data type is defined as a type of data and a
set of operations that can be performed on
that data.
• PRIMITIVE data type is on that is provided as
an integral part of AS3 language and requires
no external code.
AS3 DATA TYPES
Data Type Definition Example
INTEGER Used to store whole numbers. Age:int
UNSIGNED INTEGER Used for storing and working
with positive whole numbers.
X:uint
NUMBER A floating-point number, that can
be the number zero or any
positive or negative number that
contains a decimal point.
Pi:Number
STRING Used to store textual information. Name: String
BOOLEAN Can hold only one of two values:
TRUE or FALSE.
Answer: Boolean
VARIABLE AND CONSTANT
DECLARATIONS
• To allocate memory for a data object, programs
require a special statement called DECLARATION.
• Data objects come in two forms: VARIABLE and
CONSTANT.
• A Constant is a static data object – whose value
will not change during the program execution.
(const to declare a constant)
• A Variable is a dynamic data object. (var to
declare a variable)
IDENTIFIERS
• Identifiers are the names we assign to the
data objects we declare.
– RULE 1: Identifiers must start with a letter of the
alphabet or an underscore(_).
– RULE 2: Identifiers must consist of only letters,
digits and underscores.
– RULE 3: AS3 is case sensitive.
– RULE 4: Do not use AS3 Keywords in declaring
identifiers/Variable name.
AS3 KEYWORDS
COLOR CODES
• Variable Name –
• Data Type –
• Instance Name –
• Function Name –
• AS3 Keywords –
CONTINUOUS GROWING
var growthRate:Number = 2;
circle_mc.addEventListener(Event.ENTER_FRAME, grow);
function grow(e:Event):void
{
e.target.width += growthRate;
e.target.height += growthRate;
}
GROWING WITH TARGET SIZE
var growthRate:Number = 2;
var maxSize:Number = 150;
circle_mc.addEventListener(Event.ENTER_FRAME, grow);
function grow(e:Event):void
{
e.target.width += growthRate;
e.target.height += growthRate;
if(e.target.width>= maxSize)
{
circle_mc.removeEventListener(Event.ENTER_FRAME, grow);
}
}
GROWING AND SHRINKING (ENTER
FRAME)
var growthRate:Number = 2;
var maxSize:Number = 150;
var minSize:Number = 100;
var scaleMode:String = "grow";
circle_mc.addEventListener(Event.ENTER_FRAME, growShrink);
function growShrink(e:Event):void
{
if(scaleMode == "grow")
{
e.target.width += growthRate;
e.target.height += growthRate;
GROWING AND SHRINKING (ENTER
FRAME)if(e.target.width>= maxSize)
{
scaleMode = "shrink";
}
}
else if(scaleMode == "shrink")
{
e.target.width -= growthRate;
e.target.height -= growthRate;
if(e.target.width<= minSize)
{
scaleMode = "grow";
}
}
}
GROWING AND SHRINKING WITH
MOUSE EVENTS
var growthRate:Number = 2;
var maxSize:int = 200;
var minSize:int = 150;
var scaleMode:String = "shrink";
var clickMode:String = "start";
circle_mc.addEventListener(MouseEvent.CLICK, startStop);
function startStop(e:MouseEvent):void
{
if (clickMode == "start")
{
circle_mc.addEventListener(Event.ENTER_FRAME, growShrink);
clickMode = "stop";
}
GROWING AND SHRINKING WITH
MOUSE EVENTS
else if(clickMode == "stop")
{
circle_mc.removeEventListener(Event.ENTER_FRAME, growShrink);
clickMode = "start";
}
}
function growShrink(e:Event):void
{
if (scaleMode == "shrink")
{
e.target.width -= growthRate;
e.target.height -= growthRate;
GROWING AND SHRINKING WITH
MOUSE EVENTS
if (e.target.width<= minSize)
{
scaleMode = "grow";
}
}
else if (scaleMode == "grow")
{
e.target.width += growthRate;
e.target.height += growthRate;
if (e.target.width>= maxSize)
{
scaleMode = "shrink";
}
}
}
FADE-IN AND FADE-OUT
var fadeRate:Number = .05;
var maxVal:int = 1;
var minVal:int = 0;
var fadeMode:String = "out";
circle_mc.addEventListener(Event.ENTER_FRAME, fade);
function fade(e:Event):void
{
if(fadeMode == "out")
{
e.target.alpha -= fadeRate;
if(e.target.alpha<= minVal)
{
fadeMode = "in";
}
}
FADE-IN AND FADE-OUT
else if(fadeMode == "in")
{
e.target.alpha += fadeRate;
if(e.target.alpha>= maxVal)
{
fadeMode = "out";
}
}
}
FADE-IN AND FADE-OUT WITH
BUTTONS
var fadeRate:Number = .05;
var maxVal:int = 1;
var minVal:int = 0;
var fadeMode:String = "out";
start_btn.addEventListener(MouseEvent.CLICK, startFade);
stop_btn.addEventListener(MouseEvent.CLICK, stopFade);
FADE-IN AND FADE-OUT WITH
BUTTONS
function startFade(e:MouseEvent):void
{
circle_mc.addEventListener(Event.ENTER_FRAME, fade);
}
function stopFade(e:MouseEvent):void
{
circle_mc.removeEventListener(Event.ENTER_FRAME, fade);
}
FADE-IN AND FADE-OUT WITH
BUTTONSfunction fade(e:Event):void
{
if (fadeMode == "out")
{
e.target.alpha -= fadeRate;
if (e.target.alpha<= minVal)
{
fadeMode = "in";
}
}
else if (fadeMode == "in")
{
e.target.alpha += fadeRate;
if (e.target.alpha>= maxVal)
{
fadeMode = "out";
}
}
}
UP AND DOWN BUTTON
function goUp(e:MouseEvent):void
{
starfish_mc.y = starfish_mc.y - 10;
}
function goDown(e:MouseEvent):void
{
starfish_mc.y = starfish_mc.y + 10;
}
up_btn.addEventListener(MouseEvent.CLICK, goUp);
down_btn.addEventListener(MouseEvent.CLICK, goDown);
NEXT AND BACK BUTTON
stop();
next_btn.addEventListener(MouseEvent.CLICK, goNext);
back_btn.addEventListener(MouseEvent.CLICK, goBack);
function goNext(e:MouseEvent):void {
nextFrame();
}
function goBack(e:MouseEvent):void {
prevFrame();
}
GROWING AN OBJECT USING UP AND
DOWN BUTTON
up_btn.addEventListener(MouseEvent.CLICK, goUp);
down_btn.addEventListener(MouseEvent.CLICK,
goDown);
function goUp(e:MouseEvent):void {
starfish_mc.width += 10;
starfish_mc.height += 10;
}
function goDown(e:MouseEvent):void {
starfish_mc.width -= 10;
starfish_mc.height -= 10;
}
Ad

More Related Content

Similar to Introducing to AS3.0 programming (20)

Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
Abir ppt3
Abir ppt3Abir ppt3
Abir ppt3
abir96
 
Arrays
ArraysArrays
Arrays
RaziyasultanaShaik
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Array
ArrayArray
Array
PralhadKhanal1
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
c++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptxc++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptx
JanineCallangan
 
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
wrushabhsirsat
 
Control structure repetition Tito Lacbayen
Control structure repetition Tito LacbayenControl structure repetition Tito Lacbayen
Control structure repetition Tito Lacbayen
LacbayenEchaviaTitoJ
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in javaData types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in java
Javed Rashid
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
Bt0065
Bt0065Bt0065
Bt0065
Simpaly Jha
 
B T0065
B T0065B T0065
B T0065
Simpaly Jha
 
Ch-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxCh-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptx
ChereLemma2
 
Array
ArrayArray
Array
Kathmandu University
 
Python
PythonPython
Python
Sangita Panchal
 
Arrays in c
Arrays in cArrays in c
Arrays in c
vampugani
 
lecture2 (1).ppt variable s and operators
lecture2 (1).ppt variable s and operatorslecture2 (1).ppt variable s and operators
lecture2 (1).ppt variable s and operators
ChittyAvula
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
Terry Yoast
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
StephenOczon1
 
Abir ppt3
Abir ppt3Abir ppt3
Abir ppt3
abir96
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
c++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptxc++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptx
JanineCallangan
 
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
wrushabhsirsat
 
Control structure repetition Tito Lacbayen
Control structure repetition Tito LacbayenControl structure repetition Tito Lacbayen
Control structure repetition Tito Lacbayen
LacbayenEchaviaTitoJ
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in javaData types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in java
Javed Rashid
 
Ch-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxCh-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptx
ChereLemma2
 
lecture2 (1).ppt variable s and operators
lecture2 (1).ppt variable s and operatorslecture2 (1).ppt variable s and operators
lecture2 (1).ppt variable s and operators
ChittyAvula
 

Recently uploaded (20)

Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Ad

Introducing to AS3.0 programming

  • 1. Introducing to AS3 Programming ENGR. SOLIEL G. MUTYA DLS-CSB MAY 2016
  • 2. ACTIONSCRIPT 3.0 DATA TYPES • AS3 is a structured language as well as an object-oriented language. • It is a structured because it is built around functions. • It is an OOP because it is built around classes and objects. Data identified for I-P-O will need to be stored as data objects.
  • 3. AS3 DATA TYPES • Data type is defined as a type of data and a set of operations that can be performed on that data. • PRIMITIVE data type is on that is provided as an integral part of AS3 language and requires no external code.
  • 4. AS3 DATA TYPES Data Type Definition Example INTEGER Used to store whole numbers. Age:int UNSIGNED INTEGER Used for storing and working with positive whole numbers. X:uint NUMBER A floating-point number, that can be the number zero or any positive or negative number that contains a decimal point. Pi:Number STRING Used to store textual information. Name: String BOOLEAN Can hold only one of two values: TRUE or FALSE. Answer: Boolean
  • 5. VARIABLE AND CONSTANT DECLARATIONS • To allocate memory for a data object, programs require a special statement called DECLARATION. • Data objects come in two forms: VARIABLE and CONSTANT. • A Constant is a static data object – whose value will not change during the program execution. (const to declare a constant) • A Variable is a dynamic data object. (var to declare a variable)
  • 6. IDENTIFIERS • Identifiers are the names we assign to the data objects we declare. – RULE 1: Identifiers must start with a letter of the alphabet or an underscore(_). – RULE 2: Identifiers must consist of only letters, digits and underscores. – RULE 3: AS3 is case sensitive. – RULE 4: Do not use AS3 Keywords in declaring identifiers/Variable name.
  • 8. COLOR CODES • Variable Name – • Data Type – • Instance Name – • Function Name – • AS3 Keywords –
  • 9. CONTINUOUS GROWING var growthRate:Number = 2; circle_mc.addEventListener(Event.ENTER_FRAME, grow); function grow(e:Event):void { e.target.width += growthRate; e.target.height += growthRate; }
  • 10. GROWING WITH TARGET SIZE var growthRate:Number = 2; var maxSize:Number = 150; circle_mc.addEventListener(Event.ENTER_FRAME, grow); function grow(e:Event):void { e.target.width += growthRate; e.target.height += growthRate; if(e.target.width>= maxSize) { circle_mc.removeEventListener(Event.ENTER_FRAME, grow); } }
  • 11. GROWING AND SHRINKING (ENTER FRAME) var growthRate:Number = 2; var maxSize:Number = 150; var minSize:Number = 100; var scaleMode:String = "grow"; circle_mc.addEventListener(Event.ENTER_FRAME, growShrink); function growShrink(e:Event):void { if(scaleMode == "grow") { e.target.width += growthRate; e.target.height += growthRate;
  • 12. GROWING AND SHRINKING (ENTER FRAME)if(e.target.width>= maxSize) { scaleMode = "shrink"; } } else if(scaleMode == "shrink") { e.target.width -= growthRate; e.target.height -= growthRate; if(e.target.width<= minSize) { scaleMode = "grow"; } } }
  • 13. GROWING AND SHRINKING WITH MOUSE EVENTS var growthRate:Number = 2; var maxSize:int = 200; var minSize:int = 150; var scaleMode:String = "shrink"; var clickMode:String = "start"; circle_mc.addEventListener(MouseEvent.CLICK, startStop); function startStop(e:MouseEvent):void { if (clickMode == "start") { circle_mc.addEventListener(Event.ENTER_FRAME, growShrink); clickMode = "stop"; }
  • 14. GROWING AND SHRINKING WITH MOUSE EVENTS else if(clickMode == "stop") { circle_mc.removeEventListener(Event.ENTER_FRAME, growShrink); clickMode = "start"; } } function growShrink(e:Event):void { if (scaleMode == "shrink") { e.target.width -= growthRate; e.target.height -= growthRate;
  • 15. GROWING AND SHRINKING WITH MOUSE EVENTS if (e.target.width<= minSize) { scaleMode = "grow"; } } else if (scaleMode == "grow") { e.target.width += growthRate; e.target.height += growthRate; if (e.target.width>= maxSize) { scaleMode = "shrink"; } } }
  • 16. FADE-IN AND FADE-OUT var fadeRate:Number = .05; var maxVal:int = 1; var minVal:int = 0; var fadeMode:String = "out"; circle_mc.addEventListener(Event.ENTER_FRAME, fade); function fade(e:Event):void { if(fadeMode == "out") { e.target.alpha -= fadeRate; if(e.target.alpha<= minVal) { fadeMode = "in"; } }
  • 17. FADE-IN AND FADE-OUT else if(fadeMode == "in") { e.target.alpha += fadeRate; if(e.target.alpha>= maxVal) { fadeMode = "out"; } } }
  • 18. FADE-IN AND FADE-OUT WITH BUTTONS var fadeRate:Number = .05; var maxVal:int = 1; var minVal:int = 0; var fadeMode:String = "out"; start_btn.addEventListener(MouseEvent.CLICK, startFade); stop_btn.addEventListener(MouseEvent.CLICK, stopFade);
  • 19. FADE-IN AND FADE-OUT WITH BUTTONS function startFade(e:MouseEvent):void { circle_mc.addEventListener(Event.ENTER_FRAME, fade); } function stopFade(e:MouseEvent):void { circle_mc.removeEventListener(Event.ENTER_FRAME, fade); }
  • 20. FADE-IN AND FADE-OUT WITH BUTTONSfunction fade(e:Event):void { if (fadeMode == "out") { e.target.alpha -= fadeRate; if (e.target.alpha<= minVal) { fadeMode = "in"; } } else if (fadeMode == "in") { e.target.alpha += fadeRate; if (e.target.alpha>= maxVal) { fadeMode = "out"; } } }
  • 21. UP AND DOWN BUTTON function goUp(e:MouseEvent):void { starfish_mc.y = starfish_mc.y - 10; } function goDown(e:MouseEvent):void { starfish_mc.y = starfish_mc.y + 10; } up_btn.addEventListener(MouseEvent.CLICK, goUp); down_btn.addEventListener(MouseEvent.CLICK, goDown);
  • 22. NEXT AND BACK BUTTON stop(); next_btn.addEventListener(MouseEvent.CLICK, goNext); back_btn.addEventListener(MouseEvent.CLICK, goBack); function goNext(e:MouseEvent):void { nextFrame(); } function goBack(e:MouseEvent):void { prevFrame(); }
  • 23. GROWING AN OBJECT USING UP AND DOWN BUTTON up_btn.addEventListener(MouseEvent.CLICK, goUp); down_btn.addEventListener(MouseEvent.CLICK, goDown); function goUp(e:MouseEvent):void { starfish_mc.width += 10; starfish_mc.height += 10; } function goDown(e:MouseEvent):void { starfish_mc.width -= 10; starfish_mc.height -= 10; }
  翻译: