Creative Programming in ActionScript 3.0

8,868 views

Published on

Published in: Technology
0 Comments
14 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,868
On SlideShare
0
From Embeds
0
Number of Embeds
1,530
Actions
Shares
0
Downloads
289
Comments
0
Likes
14
Embeds 0
No embeds

No notes for slide

Creative Programming in ActionScript 3.0

  1. Creative Programming in ActionScript 3.0
  2. • Flash Platform Consultant • Lecturer Devine • Adobe Community Expert • Technical author • Full time web geek
  3. Creativity is a mental process involving the generation of new ideas or concepts, or new associations of the creative mind between existing ideas or concepts.
  4. Programming is a the process of writing, testing, debugging and maintaining the source code of computer programs.
  5. What will we talk about? • Object-Oriented Programming • Classes and instances • Inheritance • Encapsulation • Basic trigonometry • Distance between points • Polar and Cartesian coordinates • Experimentation • BitmapData • Sound Spectrum
  6. Object-Oriented Programming
  7. Classes and instances
  8. Classes • Classes are blueprints of functionality • Allow for reusable and modular code • Contain methods (functions) and properties (variables) Ball class
  9. Instances • Instances (objects) are copies based on a class blueprint • Instance property values are independent of its class Ball class Ball instance Ball instance Ball instance
  10. Example (Library panel)
  11. HelloWorld.as package { public class HelloWorld { public var name:String; public function HelloWorld(value:String) { this.name = value; trace(“Hello world from “+ this.name); } } }
  12. HelloWorld instances var myWorld:HelloWorld = new HelloWorld(“Peter”); // Hello world from Peter trace(myWorld.name); // Peter var otherWorld:HelloWorld = new HelloWorld(“Barack”); // Hello world from Barack trace(myWorld.name); // Barack
  13. Inheritance • Classes can extend each others functionality • Each class can only inherit from one super class • Use the “extends” keyword Animal class Dog class Cat class Tiger class
  14. Example (inheritance.fla)
  15. Encapsulation • Protect the inner workings of your class • Access modifiers (public, private, protected, internal) • Use getter/setter methods to provide access getter/setter other class class internals
  16. Access modifiers • public - accessible from anywhere • private - only accessible from within the class • protected - only accessible within class and subclasses • internal - only accessible within same package (default)
  17. Getter/setters • Looks like a method, behaves like a property • Provides a single entry point for setting a property • Useful for input validation private var _age:Number; public function get age():Number { return this._age; } public function set age(val:Number):void { if(val >= 18) { this._age = val; } else { trace(“you are too young”); } }
  18. Account.as package { public class Account { private var _email:String; public function set email(val:String):void { if(val.indexOf(“@”) != -1) { this._email = val; } else { trace(“invalid email”); } } } } var myAccount:Account = new Account(); myAccount.email = “peter.elst@gmail.com”;
  19. Basic Trigonometry
  20. Distance between points point 2 point 1
  21. Distance between points point 2 C B point 1 A
  22. A² + B² = C²
  23. √ d(P1,
P2)
=



(x2
‐
x1)2
+
(y 
–
y )
2 2 1
  24. Example (distance.fla)
  25. Cartesian coordinates (x,y) x y
  26. Polar coordinates (r, θ) r θ
  27. A² + B² = C² (r, θ) C B θ A
  28. Converting polar coordinates x
=
Math.cos(θ)
*
radius y
=
Math.sin(θ)
*
radius θ
is
the
angle
in
radians
  29. Example (polar-animation.fla)
  30. Experimentation
  31. flash.display.BitmapData • Allows you to get pixel level access to bitmaps • Work with color channels • Perform bitmap operations
  32. SoundMixer.computeSpectrum • Returns spectrum information of sound • ByteArray with floating point values between -1 and 1 • Raw wave form or Fast Fourier Transform (FFT) • Doesn’t work for microphone input (yet) :( • see www.getmicrophone.com
  33. Books Foundation ActionScript 3.0 Animation “Making Things Move” Object-Oriented ActionScript 3.0 Websites www.gotoandlearn.com www.levitated.net Get in touch Email: peter.elst@gmail.com Blog: www.peterelst.com Twitter: peterelst Thank you!

×