SlideShare a Scribd company logo
OO JS for AS3 Devs Object-Oriented JavaScript for ActionScript 3 Developers
Pirates vs Ninjas Pirate Ninja
JS vs AS3 Object Number String Boolean Object Object Array (Object)  Date Function Function Prototype <Script src=&quot;&quot;/> Function Object Number | int | unit String Boolean Array Dictionary Array Date Function Class Prototype Import Getter / Setter
No Strong Types in JS var myVar1; var myVar1 = 10; var myVar1, myVar2, myVar3; var myVar = []; myVar.push(&quot;foo&quot;); const EVENT_NAME = &quot;name&quot; var myVar:Object public myVar public function myFunct():String function myFunct():String package {}, class {}  extends, implements, final, internal, public, private GOOD PUPPY  BAD PUPPY 
'Classes' in JS     Everything is an Object or Function Functions are pushed to the limits A JS Class is just a Function Function 'scope' rules are used for to create public, private spaces Inheritance is wacky ( will get to this later ) Prototype is wacky ( will get to this later )  
function myClass() {      this.add = function(a, b)          {          return a + b;      }; } var c = new myClass(); c.add(1, 1); TEST IN FIREBUG
Getters / Setters function Puppy() {      var _evil = 1000;      this. getEvil  = function()      {          return _evil;      };      this. setEvil  = function(value)      {          _evil  = value;      } } var evilPuppy = new Puppy(); evilPuppy. getEvil() ;
Self Executing Functions function Puppy() {      var _evil = 999;      this.getEvil = function()      {          return _evil;      };      (function init(value)      {          _evil = v;      })(45) } var evilPuppy = new Puppy(); evilPuppy.getEvil();
Scope is a Pain! function level_1() {      var good = 20;      this.evil = 99;      var timeout = setTimeout(function()          {              console.log(good);              console.log(evil);              console.log(this.evil);          }, 500); } var x = new level_1();
Scope is a Pain - Part 2 function level_1() {      var good = 20;      this.evil = 99;      var scope = this;      var timeout = setTimeout(function()          {              console.log(good);              console.log(scope.evil);          }, 500); } var x = new level_1();
Inheritance Tons of ways to do Inheritance  I will only cover one way No &quot;extends&quot; in JS Completely different way of thinking about it Special property on Object named Prototype
function Animal() {      Animal.prototype.evil = 1000;      Animal.prototype.getColor = function()      {          return &quot;Blood Red&quot;;      } } function Puppy()  { } Puppy.prototype = Animal.prototype; var p = new Puppy(); p.getColor();
function Animal() {      Animal.prototype.evil = 1000;      Animal.prototype.getColor = function()      {          return &quot;Blood Red&quot;;      } } function Puppy()  { } new Animal(); //(GOTCHA!) Puppy.prototype = Animal.prototype; var p = new Puppy(); p.getColor();
function Animal(){      Animal.prototype.color = &quot;Blood Red&quot;;      Animal.prototype.getColor = function()      {          return &quot;Evil &quot; + this.color;      } }; var a = new Animal(); console.log(&quot;Animal Color: &quot; + a.getColor()); function Puppy() {      this.color = &quot;Blue&quot;; } Puppy.prototype = Animal.prototype; var p = new Puppy(); console.log(&quot;Puppy Color: &quot; + p.getColor());
HTML5 <canvas> tag  <body> <canvas id=&quot;gameCanvas&quot; width=&quot;600&quot; height=&quot;600&quot;></canvas> </body>
Get Pointer to <canvas> from JS // javaScript var canvas = document.getElementById('gameCanvas'); var context = canvas.getContext('2d');
Draw on <canvas> with JS // javaScript context.beginPath(); context.moveTo(0,0); context.lineTo(0,100); context.lineTo(100,100); context.lineTo(100,0); context.closePath(); context.strokeStyle = &quot;#000000&quot;; context.fill(); context.fillStyle = &quot;#CCCCCC&quot;; context.fill();
&quot;Animation&quot; (in quotes) var intervalId = setInterval(drawCanvas, 1000 / 30); function drawCanvas(){      // clear everything      context.clearRect(0,0, myWidth, myHeight);      // redraw everything      // Yes, you better know exactly       // where every pixel is at all times so       // you can redraw it at 30 FPS      // :( }
&quot;Animation&quot; (in quotes) var intervalId = setInterval(smartDrawCanvas, 1000 / 30); function smartDrawCanvas() {      // Clear only part of the canvas      context.clearRect(25, 25, 50, 50);      // redraw SOME of the canvas      // TODO .... }
Mouse Events on <canvas> Cannot listen to events on any children on the <canvas> Think of <canvas> as AS3 Bitmap You can only listen on the main <canvas> object You need to know where every 'interactive' object is the <canvas> at all times. For clicks you need to calculate what was under the pixel that was clicked on Observer pattern helps with this work
Gotchas **JS** (for each works in FF, but not Chrome) for (var x in myArray) {      var obj = myArray[x];      obj.selected = false; } **AS3** for each (var x:Object in myArray) {      x.selected = false; }
Gotchas var timeout = setTimeout(function()      {                  var x = passThruVar1;          // x is undefined!!!      }, 500,  passThruVar1 ,  passThruVar2 );

More Related Content

What's hot (20)

ZIP
Intro to Pig UDF
Chris Wilkes
 
PDF
Advanced python
EU Edge
 
PDF
Docopt
René Ribaud
 
PDF
node ffi
偉格 高
 
KEY
Gevent what's the point
seanmcq
 
PDF
EcmaScript 6 - The future is here
Sebastiano Armeli
 
KEY
XpUg Coding Dojo: KataYahtzee in Ocp way
Giordano Scalzo
 
PPT
JavaScript Functions
Brian Moschel
 
KEY
Agile Iphone Development
Giordano Scalzo
 
PDF
Stupid Awesome Python Tricks
Bryan Helmig
 
PPTX
Stop Programming in JavaScript By Luck
sergioafp
 
PPTX
Javascript Function
xxbeta
 
PDF
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
PDF
A swift introduction to Swift
Giordano Scalzo
 
PPT
Lecture05
elearning_portal
 
PDF
The Evolution of Async-Programming on .NET Platform (TUP, Full)
jeffz
 
PPTX
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
KEY
Txjs
Peter Higgins
 
PPT
C++ tutorial
sikkim manipal university
 
PPT
C++totural file
halaisumit
 
Intro to Pig UDF
Chris Wilkes
 
Advanced python
EU Edge
 
Docopt
René Ribaud
 
node ffi
偉格 高
 
Gevent what's the point
seanmcq
 
EcmaScript 6 - The future is here
Sebastiano Armeli
 
XpUg Coding Dojo: KataYahtzee in Ocp way
Giordano Scalzo
 
JavaScript Functions
Brian Moschel
 
Agile Iphone Development
Giordano Scalzo
 
Stupid Awesome Python Tricks
Bryan Helmig
 
Stop Programming in JavaScript By Luck
sergioafp
 
Javascript Function
xxbeta
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
A swift introduction to Swift
Giordano Scalzo
 
Lecture05
elearning_portal
 
The Evolution of Async-Programming on .NET Platform (TUP, Full)
jeffz
 
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
C++totural file
halaisumit
 

Similar to OO JS for AS3 Devs (20)

PDF
Js objects
anubavam-techkt
 
PPTX
Object Oriented JavaScript
Julie Iskander
 
PPTX
Intro to Canva
dreambreeze
 
PPTX
Introduction to Canvas - Toronto HTML5 User Group
dreambreeze
 
PDF
Introduction to Canvas - Toronto HTML5 User Group
bernice-chan
 
PDF
Joose - JavaScript Meta Object System
malteubl
 
KEY
The Canvas API for Rubyists
deanhudson
 
PPTX
OO in JavaScript
Gunjan Kumar
 
PPT
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
PDF
Javascript Styles and some tips
Vítor Baptista
 
PPTX
JavaScript, Beyond the Curly Braces
Chicago ALT.NET
 
PDF
Say It With Javascript
Giovanni Scerra ☃
 
PDF
Intro to Advanced JavaScript
ryanstout
 
PPT
HTML5 Canvas
Robyn Overstreet
 
PDF
HTML5 Canvas - The Future of Graphics on the Web
Robin Hawkes
 
PDF
JavaScript and UI Architecture Best Practices
Siarhei Barysiuk
 
PDF
Tamarin And Ecmascript 4
elliando dias
 
PPT
JavaScript Basics
Mats Bryntse
 
PPT
Advanced JavaScript
Stoyan Stefanov
 
Js objects
anubavam-techkt
 
Object Oriented JavaScript
Julie Iskander
 
Intro to Canva
dreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
dreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
bernice-chan
 
Joose - JavaScript Meta Object System
malteubl
 
The Canvas API for Rubyists
deanhudson
 
OO in JavaScript
Gunjan Kumar
 
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
Javascript Styles and some tips
Vítor Baptista
 
JavaScript, Beyond the Curly Braces
Chicago ALT.NET
 
Say It With Javascript
Giovanni Scerra ☃
 
Intro to Advanced JavaScript
ryanstout
 
HTML5 Canvas
Robyn Overstreet
 
HTML5 Canvas - The Future of Graphics on the Web
Robin Hawkes
 
JavaScript and UI Architecture Best Practices
Siarhei Barysiuk
 
Tamarin And Ecmascript 4
elliando dias
 
JavaScript Basics
Mats Bryntse
 
Advanced JavaScript
Stoyan Stefanov
 
Ad

More from Jason Hanson (6)

PPTX
HelloGit
Jason Hanson
 
PPT
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 
KEY
Mobile Flex - Flash Camp St. Louis
Jason Hanson
 
KEY
Maximizing Code Reuse Across Screens
Jason Hanson
 
KEY
Deep Dive into Flex Mobile Item Renderers
Jason Hanson
 
PDF
Burrito and Hero
Jason Hanson
 
HelloGit
Jason Hanson
 
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 
Mobile Flex - Flash Camp St. Louis
Jason Hanson
 
Maximizing Code Reuse Across Screens
Jason Hanson
 
Deep Dive into Flex Mobile Item Renderers
Jason Hanson
 
Burrito and Hero
Jason Hanson
 
Ad

Recently uploaded (20)

PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 

OO JS for AS3 Devs

  • 1. OO JS for AS3 Devs Object-Oriented JavaScript for ActionScript 3 Developers
  • 2. Pirates vs Ninjas Pirate Ninja
  • 3. JS vs AS3 Object Number String Boolean Object Object Array (Object)  Date Function Function Prototype <Script src=&quot;&quot;/> Function Object Number | int | unit String Boolean Array Dictionary Array Date Function Class Prototype Import Getter / Setter
  • 4. No Strong Types in JS var myVar1; var myVar1 = 10; var myVar1, myVar2, myVar3; var myVar = []; myVar.push(&quot;foo&quot;); const EVENT_NAME = &quot;name&quot; var myVar:Object public myVar public function myFunct():String function myFunct():String package {}, class {}  extends, implements, final, internal, public, private GOOD PUPPY  BAD PUPPY 
  • 5. 'Classes' in JS     Everything is an Object or Function Functions are pushed to the limits A JS Class is just a Function Function 'scope' rules are used for to create public, private spaces Inheritance is wacky ( will get to this later ) Prototype is wacky ( will get to this later )  
  • 6. function myClass() {      this.add = function(a, b)          {          return a + b;      }; } var c = new myClass(); c.add(1, 1); TEST IN FIREBUG
  • 7. Getters / Setters function Puppy() {      var _evil = 1000;      this. getEvil = function()      {          return _evil;      };      this. setEvil = function(value)      {          _evil  = value;      } } var evilPuppy = new Puppy(); evilPuppy. getEvil() ;
  • 8. Self Executing Functions function Puppy() {      var _evil = 999;      this.getEvil = function()      {          return _evil;      };      (function init(value)      {          _evil = v;      })(45) } var evilPuppy = new Puppy(); evilPuppy.getEvil();
  • 9. Scope is a Pain! function level_1() {      var good = 20;      this.evil = 99;      var timeout = setTimeout(function()          {              console.log(good);              console.log(evil);              console.log(this.evil);          }, 500); } var x = new level_1();
  • 10. Scope is a Pain - Part 2 function level_1() {      var good = 20;      this.evil = 99;      var scope = this;      var timeout = setTimeout(function()          {              console.log(good);              console.log(scope.evil);          }, 500); } var x = new level_1();
  • 11. Inheritance Tons of ways to do Inheritance  I will only cover one way No &quot;extends&quot; in JS Completely different way of thinking about it Special property on Object named Prototype
  • 12. function Animal() {      Animal.prototype.evil = 1000;      Animal.prototype.getColor = function()      {          return &quot;Blood Red&quot;;      } } function Puppy()  { } Puppy.prototype = Animal.prototype; var p = new Puppy(); p.getColor();
  • 13. function Animal() {      Animal.prototype.evil = 1000;      Animal.prototype.getColor = function()      {          return &quot;Blood Red&quot;;      } } function Puppy()  { } new Animal(); //(GOTCHA!) Puppy.prototype = Animal.prototype; var p = new Puppy(); p.getColor();
  • 14. function Animal(){      Animal.prototype.color = &quot;Blood Red&quot;;      Animal.prototype.getColor = function()      {          return &quot;Evil &quot; + this.color;      } }; var a = new Animal(); console.log(&quot;Animal Color: &quot; + a.getColor()); function Puppy() {      this.color = &quot;Blue&quot;; } Puppy.prototype = Animal.prototype; var p = new Puppy(); console.log(&quot;Puppy Color: &quot; + p.getColor());
  • 15. HTML5 <canvas> tag  <body> <canvas id=&quot;gameCanvas&quot; width=&quot;600&quot; height=&quot;600&quot;></canvas> </body>
  • 16. Get Pointer to <canvas> from JS // javaScript var canvas = document.getElementById('gameCanvas'); var context = canvas.getContext('2d');
  • 17. Draw on <canvas> with JS // javaScript context.beginPath(); context.moveTo(0,0); context.lineTo(0,100); context.lineTo(100,100); context.lineTo(100,0); context.closePath(); context.strokeStyle = &quot;#000000&quot;; context.fill(); context.fillStyle = &quot;#CCCCCC&quot;; context.fill();
  • 18. &quot;Animation&quot; (in quotes) var intervalId = setInterval(drawCanvas, 1000 / 30); function drawCanvas(){      // clear everything      context.clearRect(0,0, myWidth, myHeight);      // redraw everything      // Yes, you better know exactly       // where every pixel is at all times so       // you can redraw it at 30 FPS      // :( }
  • 19. &quot;Animation&quot; (in quotes) var intervalId = setInterval(smartDrawCanvas, 1000 / 30); function smartDrawCanvas() {      // Clear only part of the canvas      context.clearRect(25, 25, 50, 50);      // redraw SOME of the canvas      // TODO .... }
  • 20. Mouse Events on <canvas> Cannot listen to events on any children on the <canvas> Think of <canvas> as AS3 Bitmap You can only listen on the main <canvas> object You need to know where every 'interactive' object is the <canvas> at all times. For clicks you need to calculate what was under the pixel that was clicked on Observer pattern helps with this work
  • 21. Gotchas **JS** (for each works in FF, but not Chrome) for (var x in myArray) {      var obj = myArray[x];      obj.selected = false; } **AS3** for each (var x:Object in myArray) {      x.selected = false; }
  • 22. Gotchas var timeout = setTimeout(function()      {                  var x = passThruVar1;          // x is undefined!!!      }, 500, passThruVar1 , passThruVar2 );

Editor's Notes

  • #7: function myClass() {      this.add = function(a, b)          {          return a + b;      }; } var c = new