introducing to as3.0 programming
TRANSCRIPT
![Page 1: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/1.jpg)
Introducing to AS3 Programming
ENGR. SOLIEL G. MUTYADLS-CSB
MAY 2016
![Page 2: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/2.jpg)
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.
![Page 3: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/3.jpg)
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.
![Page 4: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/4.jpg)
AS3 DATA TYPESData 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
![Page 5: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/5.jpg)
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)
![Page 6: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/6.jpg)
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.
![Page 7: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/7.jpg)
AS3 KEYWORDS
![Page 8: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/8.jpg)
COLOR CODES
• Variable Name –
• Data Type –
• Instance Name –
• Function Name –
• AS3 Keywords –
![Page 9: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/9.jpg)
CONTINUOUS GROWINGvar growthRate:Number = 2; circle_mc.addEventListener(Event.ENTER_FRAME, grow); function grow(e:Event):void{e.target.width += growthRate;
e.target.height += growthRate;}
![Page 10: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/10.jpg)
GROWING WITH TARGET SIZEvar 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); }}
![Page 11: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/11.jpg)
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;
![Page 12: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/12.jpg)
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"; } }}
![Page 13: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/13.jpg)
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";}
![Page 14: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/14.jpg)
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;
![Page 15: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/15.jpg)
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";}
}}
![Page 16: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/16.jpg)
FADE-IN AND FADE-OUTvar 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";}}
![Page 17: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/17.jpg)
FADE-IN AND FADE-OUTelse if(fadeMode == "in"){
e.target.alpha += fadeRate;if(e.target.alpha>= maxVal){
fadeMode = "out";}
}}
![Page 18: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/18.jpg)
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);
![Page 19: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/19.jpg)
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);}
![Page 20: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/20.jpg)
FADE-IN AND FADE-OUT WITH BUTTONS function 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";}
}}
![Page 21: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/21.jpg)
UP AND DOWN BUTTONfunction 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);
![Page 22: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/22.jpg)
NEXT AND BACK BUTTONstop(); next_btn.addEventListener(MouseEvent.CLICK, goNext);back_btn.addEventListener(MouseEvent.CLICK, goBack); function goNext(e:MouseEvent):void {
nextFrame(); }function goBack(e:MouseEvent):void {
prevFrame(); }
![Page 23: Introducing to AS3.0 programming](https://reader036.vdocuments.site/reader036/viewer/2022081605/58f0ccd01a28ab51778b4649/html5/thumbnails/23.jpg)
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;
}