Programming - Workshop 1

2,112 views

Published on

This is the first part of my workshop on programming. We start from scratch, explaining introducing programming in Actionscript 3, the programming process, variables, boolean logic, loops and mathematical functions.

Published in: Education, Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,112
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
163
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Programming - Workshop 1

  1. 1. Programming Cas Lemmens - Workshop 1
  2. 2. About me Cas Lemmens Got my knowledge on Programming by Studying Computer Science at the university of Ghent Studying and working with frameworks Playing around in Flash
  3. 3. Why this workshop? Lots of demand We can build great things! I feel lonely Good point on your CV
  4. 4. The goal Learn programming ffs! Learning Object Oriented Programming Learning Model - View - Controller Managing a programming project Exploring the Flash & Flex libraries
  5. 5. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Arrays Methods & scopes Methods Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  6. 6. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Arrays Methods & scopes Methods Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  7. 7. Before we start... Code-lover ≠ Code-expert Ask questions! Tell me when I have to slow down! Try to focus on the global method Experiment!!
  8. 8. Introduction to Flash & Actionscript 3
  9. 9. Why Actionscript 3? Lots of demand Great learning language Used in Flash, Flex and After Effects
  10. 10. Other languages Web-based Application based Script languages PHP Java Javascript ASP C, C++, Obective Applescript C, C# Ruby Lingo Python JSP Perl ...
  11. 11. Other languages Web-based Application based Script languages PHP Java Javascript ASP C, C++, Obective Applescript C, C# Ruby Lingo Python JSP Perl ... OOP MVC OOP MVC proof proof proof proof
  12. 12. How to program in Flash?
  13. 13. How to program in Flash?
  14. 14. How to program in Flash? Library Text Buttons
  15. 15. How to program in Flash? Library Text Buttons
  16. 16. How to program in Flash? Library Text Buttons
  17. 17. How to program in Flash? Library Text Buttons
  18. 18. How to program in Flash?eline Tim based Library Text Buttons
  19. 19. How to program in Flash?
  20. 20. How to program in Flash? Library Text Buttons
  21. 21. How to program in Flash? Source Library Text Buttons
  22. 22. How to program in Flash? Source Library Text Buttons
  23. 23. How to program in Flash? Source Library Text Buttons
  24. 24. How to program in Flash?ject Ob based Source Library Text Buttons
  25. 25. Programming process
  26. 26. Writing
  27. 27. Think! Writing
  28. 28. Think! Writing Compile
  29. 29. Think! Writing Compile ! Error
  30. 30. Think! Success Writing ✓ Compile ! Error
  31. 31. Think! Success Writing ✓ Compile Testing ! Error
  32. 32. Think! Success Writing ✓ Compile Testing ! ! Error Error
  33. 33. Think! Success Success Writing ✓ ✓ Compile Testing Done! ! ! Error Error
  34. 34. Think! Success Success Writing ✓ ✓ Compile Testing Done! ! ! Error Debugging Error
  35. 35. Writing
  36. 36. Writing
  37. 37. Writing
  38. 38. Writing Compile
  39. 39. Writing Compile
  40. 40. Writing Compile
  41. 41. Writing Compile Debug
  42. 42. Writing Compile Debug
  43. 43. Writing Compile Debug
  44. 44. Writing Compile Debug Testing
  45. 45. Writing Compile Debug Testing
  46. 46. Writing Compile Debug Testing
  47. 47. Writing Compile Debug Testing Debug
  48. 48. Writing Compile Debug Testing Debug
  49. 49. Exercise 1 Hello world!
  50. 50. Some tips before we start: comment! For a single line comment: // this is my comment For multiple line comments: /* I can write my comment across multiple lines */
  51. 51. Procedural programming Variables
  52. 52. var welcome:String = “Hello World!”;
  53. 53. var welcome:String = “Hello World!”; keyword for defining a new variable
  54. 54. var welcome welcome:String = “Hello World!”;
  55. 55. var welcome welcome:String = “Hello World!”; name of the variable no capital as first letter! no number as first letter! symbols for special reason separate words by capitals e.g. welcomeText and not welcometext
  56. 56. var welcome:String = “Hello World!”; String
  57. 57. var welcome:String = “Hello World!”; String type of the variable defines characteristics defines abilities
  58. 58. Native types of variables String: textual data (string or character) Boolean: logical states (true or false) Number: floating point numbers (fractional) int: integer numbers uint: positive integer numbers Array: an ordered list Error: a program error Date: specific point in time Math: common mathematical operations RegExp: tool for searching and replacing Function: reusable set of instructions Object: default basic features
  59. 59. Native types of variables String: textual data (string or character) Boolean: logical states (true or false) Number: floating point numbers (fractional) int: integer numbers uint: positive integer numbers Array: an ordered list Error: a program error Date: specific point in time Math: common mathematical operations RegExp: tool for searching and replacing Function: reusable set of instructions Object: default basic features
  60. 60. var welcome:String = “Hello World!” World!”;
  61. 61. var welcome:String = “Hello World!” World!”; value of the variable
  62. 62. var welcome:String = “Hello World!”; This defines the variable welcome with the value “Hello World!”
  63. 63. var welcome:String = “Hello World!”; PHP $welcome = “Hello World!”; C# string welcome = “Hello World!”;
  64. 64. var welcome:String = “Hello World!”;
  65. 65. var welcome:String = “Hello World!”; var welcome:Boolean = true;
  66. 66. var welcome:String = “Hello World!”; var welcome:Boolean = true; var welcome:Number = 2.34;
  67. 67. var welcome:String = “Hello World!”; var welcome:Boolean = true; var welcome:Number = 2.34; var welcome:int = -5;
  68. 68. var welcome:String = “Hello World!”; var welcome:Boolean = true; var welcome:Number = 2.34; var welcome:int = -5; var welcome:uint = 3;
  69. 69. Exercise 2 Variables
  70. 70. Procedural programming Mathematical functions
  71. 71. Doing the math!
  72. 72. Doing the math! var player1:Number = 6;
  73. 73. Doing the math! var player1:Number = 6; var player2:Number = 2;
  74. 74. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number =
  75. 75. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 + player2;
  76. 76. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 + player2; result is 8
  77. 77. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number =
  78. 78. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 - player2;
  79. 79. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 - player2; result is 4
  80. 80. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number =
  81. 81. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 * player2;
  82. 82. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 * player2; result is 12
  83. 83. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number =
  84. 84. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 / player2;
  85. 85. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 / player2; result is 3
  86. 86. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number =
  87. 87. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 % player2;
  88. 88. Doing the math! var player1:Number = 6; var player2:Number = 2; var result:Number = player1 % player2; result is 0
  89. 89. Doing the math! var player1:Number = 5; var player2:Number = 2; var result:Number =
  90. 90. Doing the math! var player1:Number = 5; var player2:Number = 2; var result:Number =
  91. 91. Doing the math! var player1:Number = 5; var player2:Number = 2; var result:Number = player1 % player2;
  92. 92. Doing the math! var player1:Number = 5; var player2:Number = 2; var result:Number = player1 % player2; result is 1
  93. 93. Exercise 3 Math class!
  94. 94. Procedural programming Boolean logic
  95. 95. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean =
  96. 96. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean =
  97. 97. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 > player2;
  98. 98. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 > player2; result is true
  99. 99. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 > player2; Bigge r result is true than
  100. 100. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean =
  101. 101. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 < player2;
  102. 102. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 < player2; result is false
  103. 103. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 < player2; Smal ler result is false than
  104. 104. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean =
  105. 105. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 <= player2;
  106. 106. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 <= player2; result is false
  107. 107. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 <= player2; Smal ler or eq ual result is false than
  108. 108. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean =
  109. 109. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 >= player2;
  110. 110. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 >= player2; result is true
  111. 111. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 >= player2; Bigge r or eq ual result is true than
  112. 112. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean =
  113. 113. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 == player2;
  114. 114. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 == player2; result is false
  115. 115. Boolean logic var player1:Number = 5; var player2:Number = 2; var result:Boolean = player1 == player2; Equa l to result is false
  116. 116. player1 == 5 player1 = 5
  117. 117. Condition: returns true or false. Values remain unchanged! player1 == 5 player1 = 5
  118. 118. Condition: returns true or false. Values remain unchanged! player1 == 5 Variable player1 gets the value 5. Values change! player1 = 5
  119. 119. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean =
  120. 120. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = player1 || player2;
  121. 121. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = player1 || player2; result is true
  122. 122. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = player1 || player2; OR result is true
  123. 123. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean =
  124. 124. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = player1 && player2;
  125. 125. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = player1 && player2; result is false
  126. 126. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = player1 && player2; AND result is false
  127. 127. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean =
  128. 128. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = !player1;
  129. 129. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = !player1; result is false
  130. 130. Boolean logic var player1:Boolean = true; var player2:Boolean = false; var result:Boolean = !player1; NOT result is false
  131. 131. Exercise 4 Boolean logic
  132. 132. false && false =
  133. 133. false && false = false
  134. 134. false && false = false true || false || true =
  135. 135. false && false = false true || false || true = true
  136. 136. false && false = false true || false || true = true !true || false || false =
  137. 137. false && false = false true || false || true = true !true || false || false = false
  138. 138. false && false = false true || false || true = true !true || false || false = false !false && true && true =
  139. 139. false && false = false true || false || true = true !true || false || false = false !false && true && true = true
  140. 140. false && false = false true || false || true = true !true || false || false = false !false && true && true = true (true || false) && false =
  141. 141. false && false = false true || false || true = true !true || false || false = false !false && true && true = true (true || false) && false = false
  142. 142. false && false = false true || false || true = true !true || false || false = false !false && true && true = true (true || false) && false = false !(false && false) || false =
  143. 143. false && false = false true || false || true = true !true || false || false = false !false && true && true = true (true || false) && false = false !(false && false) || false = false
  144. 144. false && false = false true || false || true = true !true || false || false = false !false && true && true = true (true || false) && false = false !(false && false) || false = false !(true || ((!false && true) || true)) =
  145. 145. false && false = false true || false || true = true !true || false || false = false !false && true && true = true (true || false) && false = false !(false && false) || false = false !(true || ((!false && true) || true)) = false
  146. 146. 5 < 9
  147. 147. 5 < 9 true
  148. 148. 5 < 9 true 5 > 5
  149. 149. 5 < 9 true 5 > 5 false
  150. 150. 5 < 9 true 5 > 5 false 5 >= 5
  151. 151. 5 < 9 true 5 > 5 false 5 >= 5 true
  152. 152. 5 < 9 true 5 > 5 false 5 >= 5 true 5 != 5
  153. 153. 5 < 9 true 5 > 5 false 5 >= 5 true 5 != 5 false
  154. 154. 5 < 9 true 5 > 5 false 5 >= 5 true 5 != 5 false (3 < 2) && (7 >= 7)
  155. 155. 5 < 9 true 5 > 5 false 5 >= 5 true 5 != 5 false (3 < 2) && (7 >= 7) false
  156. 156. 5 < 9 true 5 > 5 false 5 >= 5 true 5 != 5 false (3 < 2) && (7 >= 7) false !(5 <= 3) || ((5 > 3) && (3 > 2))
  157. 157. 5 < 9 true 5 > 5 false 5 >= 5 true 5 != 5 false (3 < 2) && (7 >= 7) false !(5 <= 3) || ((5 > 3) && (3 > 2)) true
  158. 158. Procedural programming Loops
  159. 159. How can I display this? 1x6= 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 52 10 x 6 = 60
  160. 160. Common loops While-loop For-loop Switch-loop Do while-loop
  161. 161. while loop while(condition) { // Do something } The loop will keep on going until the condition is false.
  162. 162. How can I display this? 1x6= 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 52 10 x 6 = 60
  163. 163. while loop while(condition) { // Do something }
  164. 164. while loop var counter:Number = 1; while(condition) { // Do something }
  165. 165. while loop var counter:Number = 1; while(counter < 11) { // Do something }
  166. 166. while loop var counter:Number = 1; while(counter <= 10) { // Do something }
  167. 167. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { // Do something }
  168. 168. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); }
  169. 169. Exercise 5 While loop
  170. 170. while loop ! Infinite loop
  171. 171. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); }
  172. 172. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  173. 173. for loop for(initialize, condition, update) { // Do something } The loop will start with the initialization, and do the update after every loop. The loop will keep on going until the condition is falls.
  174. 174. for loop for(initialize, condition, update) { // Do something }
  175. 175. for loop 1 for(initialize, condition, update) { // Do something }
  176. 176. for loop 1 for(initialize, condition, 2 update) { // Do something }
  177. 177. for loop 1 for(initialize, condition, 2 update) { // Do something 3 }
  178. 178. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  179. 179. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  180. 180. What did we initialize before the loop? var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  181. 181. What did we initialize before the loop? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  182. 182. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  183. 183. for loop 1 for(var counter:Number = 1, condition, 2 update) 4 { // Do something 3 }
  184. 184. What was the condition? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  185. 185. What was the condition? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  186. 186. for loop 1 for(var counter:Number = 1, condition, 2 update) 4 { // Do something 3 }
  187. 187. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { // Do something 3 }
  188. 188. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  189. 189. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { 3 trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  190. 190. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { 3 trace(counter + “ x “ + table + “ = “ + (counter * table)); 4 counter = counter + 1; }
  191. 191. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { // Do something 3 }
  192. 192. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { trace(counter + “ x “ + table + “ = “ + (counter * table)); 3 }
  193. 193. for loop 1 for(var counter:Number = 1, counter <= 10, 2 counter = counter + 1) 4 { trace(counter + “ x “ + table + “ = “ + (counter * table)); 3 }
  194. 194. while-loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  195. 195. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } }
  196. 196. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  197. 197. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  198. 198. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  199. 199. Exercise 6 For loop
  200. 200. No homework, but please... Overlook it... Experiment with it... Ask questions! Remember: this is only the start! So please, get this!
  201. 201. Q&A
  202. 202. Thanks!

×