Variables & datatypes Flash ActionScript Introduction to.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Java Syntax Primitive data types Operators Control statements.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Fourth Edition
JavaScript, Third Edition
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Variables & Data types Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
2440: 211 Interactive Web Programming Expressions & Operators.
CS0004: Introduction to Programming Variables – Strings.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 2: Using Data.
Chapter 2 Elementary Programming
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introducing JavaScript. Goals By the end of this lecture you should … Be able to describe the differences among object methods, object properties and.
Functions & Objects Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
CS346 Javascript -3 Module 3 JavaScript Variables.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
XP Tutorial 8 Adding Interactivity with ActionScript.
Copyright Curt Hill Variables What are they? Why do we need them?
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
Variables and Types Java Part 3. Class Fields  Aka member variable, field variable, instance variable, class variable.  These are the descriptors of.
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
var variableName:datatype;
Chapter 6 JavaScript: Introduction to Scripting
Java Variables and Types
Elementary Programming
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Starting JavaProgramming
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
WEB PROGRAMMING JavaScript.
Chapter 2: Basic Elements of Java
Chapter 2: Java Fundamentals
elementary programming
Chapter 2: Java Fundamentals
The Data Element.
Introducing JavaScript
Chap 2. Identifiers, Keywords, and Types
The Data Element.
Presentation transcript:

Variables & datatypes Flash ActionScript Introduction to

Variables A variable is a place to store information A variable is a place to store information It has a name and a type It has a name and a type Variables are used to make the code dynamic Variables are used to make the code dynamic Tip: Declare your variables first (on top)

Datatypes The datatype defines the type of data a variable or actionscript element can hold The datatype defines the type of data a variable or actionscript element can hold Primitive datatypes: Primitive datatypes:  String, Number, Boolean, (undefined, null) Complex datatypes: Complex datatypes:  Object, MovieClip, Void Void: indicates that a function does not return a value

Naming variables Variable names can only contain letters, numbers, and dollar signs ($) Variable names can only contain letters, numbers, and dollar signs ($) All variables must have unique names All variables must have unique names Start variables with a lowercase letter Start variables with a lowercase letter Use mixed case for concatenated words Use mixed case for concatenated words Don't use reserved words: this, menu, private, video, etc. Don't use reserved words: this, menu, private, video, etc. Variables are are case-sensitive Variables are are case-sensitive Don't use the same variable name with different cases Don't use the same variable name with different cases Keep variables as short as possible while retaining clarity Keep variables as short as possible while retaining clarity Example, with strict datatyping: var xSpeed:Number;

Datatype: String Strings are sequences of characters, numbers and punctuation marks. These are enclosed within single (') or double (") quotation marks Strings are sequences of characters, numbers and punctuation marks. These are enclosed within single (') or double (") quotation marks//declaration var myURL_string:String; //assignment myURL_string = "

String functions var my_string:String; //concatenation my_string = ”Hi ”+”there!”; //traces to Hi there! //getting substring var sub_string:String = my_string.substring(3, my_string.length); //making all characters uppercase var upper_string:String = sub_string.toUpperCase(); trace(upper_string);//yields THERE!

Datatype: Number Numbers represent numerical values, both integers and floats Numbers represent numerical values, both integers and floats//declaration var length:Number; //assignment length = 1100; length = -22 length = length = 100/3; //traces to length = 1/0; //traces to Infinity x = 5; y = ”56” //from a text z = x + y; //(z = ”556”) z = x + Number(y); //(z = 61)

Number Variable declaration, assignment and initialization Variable declaration, assignment and initialization//declaration var height:Number; //assignment height = 200;//literal value height = anotherVariable;//value from another variable //initialization(declaration and assignment on the //same code line) var width:Number = 300;

Datatype: Boolean Boolean represents a boolean value, possible values: true or false Boolean represents a boolean value, possible values: true or false Converts the parameter expression to a Boolean value and returns true or false Converts the parameter expression to a Boolean value and returns true or false var isLoaded:Boolean; isLoaded = true;

Array Arrays are lists of data under which each item is identified by its order within the list Arrays are lists of data under which each item is identified by its order within the list An array can be made up of primitive type values like strings, numeric values, booleans or complex type values like other arrays or objects An array can be made up of primitive type values like strings, numeric values, booleans or complex type values like other arrays or objects music_array = new Array(); music_array = [“Metallica”, “Bruce Springsteen”, “U2”, “Iron Maiden”, “David Gray”, “Van Morrison”]; music_array.length // traces the lenght of the array music_array[1]; // traces Bruce Springsteen music_array.slice(2,4); //traces U2, Iron Maiden

Object A collection of properties that describes the object A collection of properties that describes the object Ex. An apple has properties like smell, color, size and position The object can contain different datatypes The object can contain different datatypes Positve: Return the Object (all properties) in one call Positve: Return the Object (all properties) in one call Example: How to create your own object: var user:Object = new Object(); user.name = "Irving"; user.age = 32; user.hobby = “Drinking!";

Arithmetic operators Arithmetic operators Arithmetic operators +, -, *, /, % ++, - - +=, -=, *=, /=, %= Increment ++, and decrement - - Increment ++, and decrement - - Increments/decrements a variable by 1 var x:Number = 10; x++; trace(x);//yields 11 x--; trace(x);//yields 10

Precedence The answer depends on operator precedence The answer depends on operator precedence var i:Number; i = * 10 / 2; //traces 25 You can override precedence by using parenteses You can override precedence by using parenteses var i:Number; i=(12 + 3) * 10 / 2; trace(i);//yields 75

Variables & Text (1/2) Static Text: Animations, common use, standard fonts Static Text: Animations, common use, standard fonts Input Text: Inputtext, forms, variables etc Input Text: Inputtext, forms, variables etc Dynamic Text: Dynamic text, variable in & output, non-standard fonts (embed fonts), scrolling text, loading of text (html-data) Dynamic Text: Dynamic text, variable in & output, non-standard fonts (embed fonts), scrolling text, loading of text (html-data) for example by :  Textfil  XML  Databas

Variables & Text (1/2)  An Input- and/or a dynamic textfield/box, could be connected to a variable ( my_variable )  These textfields could also have an instance name ( my_txt )

Variables and Buttons Example: A button, input textfield and output field Example: A button, input textfield and output field //declare variables var input_string:String = ""; var output_string:String = ""; //button/function for output my_btn.onPress = function(){ output_string = input_string; }