SlideShare a Scribd company logo
Stuff You Didn't Know
 About ActionScript


      Christophe Herreman
           @herrodius
... or an exploration of the ActionScript 3 language in which
you might discover new things that you were not aware of
and that one day might come in handy, or in which you will
want to scream out WTF's so loud that the whole venue
might think I'm presenting naked whilst in reality you are just
looking at a piece of ActionScript code that is so counter-
intuitive or looks rather puzzling you wonder how anyone
came up with the idea to implement certain parts of the API
this way, which on the other hand makes the language also
very fun to work with once you know how to deal with these
peculiarities and it becomes clear that ActionScript is
actually pretty cool and powerful ...
About me
Run Stack & Heap, a development, consulting and training
company based in Belgium specializing in Web / RIA
Development

Certified expert Flex with AIR, loved Flash since 1999

Founder of Spring ActionScript and AS3Commons

Apache Flex committer
Operators
Equality "=="
Checks if 2 values are equal, and applies data conversion if
the values have different data types.

"hello" == "hello"            // true
"5" == 5                      // true
true == 1                     // true
false == 0                       // true
"true" == true                // false
null == undefined             // true
Strict Equality "==="
Checks if 2 values and their types are equal.

"hello" === "hello"           // true
"5" === 5                     // compile error
true === 1                       // false
false === 0                   // false
"true" === true                  // false
null === undefined            // false
Equality "=="
Complex data types are compared by reference, not value.

var a:Array = [1, 2, 3];
var b:Array = [1, 2, 3];

a == b      // false

var c:Array = a;

a == c      // true
Conditional "?:"
Known as the Ternary Operator.

var result:Boolean = (a > b) ? x : y;

// shorthand for

var result:Boolean;
if (a > b) {
   result = x;
} else {
   result = y;
}
Logical OR "||="
function (a:Object) {
   a ||= new Object();
}

// shorthand for

function (a:Object) {
   if (a === null) {
      a = new Object();
   }
}
Logical AND "&&="
function toHTMLTag (s:String) {
   s &&= "<" + s + ">";
   return s;
}

// shorthand for

function toHTMLTag (s:String) {
   if (s !== null && (s.length > 0))
      s = "<" + s + ">";
   return s;
}
"as"
Casts a value to another data type, returning null if the cast
fails.

"hello" as String           // "hello"
5 as String                 // null
true as MyClass                // null

String("hello")                // "hello"
String(5)                   // "5"
MyClass(true)               // Runtime Error
"is" vs "instanceof"
Check if a value is of a certain data type.

var s:Sprite = new Sprite();

s is Sprite                    // true
s is DisplayObject             // true
s is IEventDispatcher          // true

s instanceof Sprite           // true
s instanceof DisplayObject    // true
s instanceof IEventDispatcher // false
"::" name qualifier
Identifies the namespace of an object.

public namespace Dutch;
public namespace French;

Dutch function hello():String {
   return "hallo";
}

French function hello():String {
   return "bonjour";
}
"::" name qualifier

Dutch::hello()    // "hallo"
French::hello()      // "bonjour"
"::" name qualifier
"public", "private", "protected", "internal"
are also namespaces.

public function get a():String;
private function set a(value:String);

trace(a)       // compile error
a = "hello"    // compile error

trace(public::a)
private::a = "hello"
"in" vs Object.hasOwnProperty
Check if an object contains a certain
property.

"CASEINSENSITIVE" in Array              //   true
"CASEINSENSITIVE" in []                 //   false
"length" in Array                       //   true
"length" in []                          //   true

[].hasOwnProperty("CASEINSENSITIVE") // false
[].hasOwnProperty("length")          // true
"arguments"
An array available in each function that contains the
arguments passed to the function.
function myFunction (x:int) {
   for(var i:uint=0; i<arguments.length; i++){
     trace(arguments[i]);
   }
}
myFunction(1, 2, 3);
// 1
// 2
// 3
"..." Rest Arguments
Pass an arbitrary number of extra arguments to a function.

function myFunction (x:int, ... rest) {
   for (var i:uint = 0; i< rest.length; i++) {
     trace(rest[i]);
   }
}

myFunction(1, 2, 3);
// 2
// 3
Tips & Tricks
Object creation
var a:Array = new Array();
var a:Array = [];              // faster

var o:Object = new Object();
var o:Object = {};             // faster

var v:Vector.<String> = new Vector.<String>();
v.push("a");
v.push("b");

var v:Vector.<String> = new <String>["a", "b"];
Object References
var a:Object = {};
a.name = "John";

var b:Object = a;
b.name = "Elvis";

trace(a.name);       // output "Elvis"
Object Copies
Create deep or shallow copies depending on
the scenario.

// deep copy

private function clone(obj:Object):Object {
   var bytes:ByteArray = new ByteArray();
   bytes.writeObject(obj);
   bytes.position = 0;
   return bytes.readObject();
}
Events
Always override the "clone" method in an Event subclass.
Prevents runtime type coercion errors when redispatching.

class MyEvent extends Event {
   public function MyEvent(data:Object){
     _data = data;
   }
   override public function clone():Event {
     return new MyEvent(_data);
   }
}
for...in vs. for each...in
var arr:Array = ["a", "b", "c"];

// loops through keys (0, 1, 2)
for ( var i in arr ) {
   trace( i );
}

// loop through values ("a", "b", "c")
for each ( var s:String in arr ) {
   trace( s );
}

Gotcha: order is not guaranteed, use for loop with counter
trace()
You can pass multiple arguments to the trace() method. No
need to compose a string.

trace(new Date(2012, 4, 22), "Aloha", Math.PI, true);

// Tue May 22 00:00:00 GMT+0200 2012 Aloha 3.141592653589793
true
Labeled Loops
Use "label" on a loop to name it. Useful when breaking from
nested loops.

mainLoop:
for (var i:uint = 0; i<10; i++) {
   for (var j:uint = 0; j<10; j++) {
       if (i == 5 && j == 7) {
          break mainLoop;
       }
   }
}
Global Functions
Declare a single function in an *.as file and name the file the
same as the function.

// in file: myGlobalFunction.as
package {
   function myGlobalFunction():void {
     trace("in myGlobalFunction");
   }
}
Adding Methods to Built-in Classes
Extend the behavior of built-in classes by adding methods to
the prototype.

Array.prototype.removeItem = function (item:*):void {
   var index:int = this.indexOf(item);
   if (index > -1) {
       this.splice(index, 1);
   }
};

var a:Array = [1, 2, 3];
a.removeItem(2);
trace(a); // 1, 3
Gotchas
   &
 WTF's
Casting
var o:MyObject = new MyObject();
var o1:MyObject = MyObject(o);
var o2:MyObject = o as MyObject; // o1 === o2

var a:Array = [1, 2, 3];
var a1:Array = Array(a);   // new Array !!!
var a2:Array = a as Array; // a1 !== a2

Also the case with Date and Error classes. Watch out!
Casting to Boolean
Boolean(true)        // true
Boolean(false)       // false
Boolean(0)              // false
Boolean(1)              // true
Boolean(-1)          // true
Boolean("true")      // true
Boolean("false")     // true
Boolean("")          // false
Boolean(" ")         // true
Boolean("0")         // true
Boolean("1")         // true
Boolean(null)        // false
Boolean(undefined)   // false
Boolean(Object)      // true
Boolean({})          // true
Array class
var a:Array = new Array();       // empty array
var a:Array = [];                   // empty array

var a:Array = new Array(10);     // array with length 10
var a:Array = [10];              // array with 1 element: 10

var a:Array = new Array(1, 2, 3); // array with values 1, 2,
3
var a:Array = [1, 2, 3];          // array with values 1, 2,
3
Date class
new   Date();                // current date
new   Date(2012);               // 01/01/1970 01:00:
02
new   Date(2012, 1);    // 01/02/2012 00:00:00
new   Date(2012, 1, 1); // 01/02/2012 00:00:00

public function Date(
   yearOrTimevalue:Object,
   month:Number,             // 0 to   11
   date:Number = 1,             // 1   to 31
   hour:Number = 0,             // 0   to 23
   minute:Number = 0,        // 0 to   59
   second:Number = 0,        // 0 to   59
   millisecond:Number = 0)   // 0 to   999
Throwing Parties
You can throw more than just errors.

class AwesomeParty {}

try {
   throw new AwesomeParty();
} catch (party:AwesomeParty) {
   // go loose at moNo!
}

Practical use?
More info
ActionScript 3 Language Reference
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/


ActionScript 3 Language Specification
http://livedocs.adobe.com/specs/actionscript/3/


Twitter
@herrodius, @stackandheap

Stack & Heap Labs
http://labs.stackandheap.com
Questions ?
Thank you !

More Related Content

What's hot

What are arrays in java script
What are arrays in java scriptWhat are arrays in java script
What are arrays in java script
Miguel Silva Loureiro
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Michael Girouard
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
Michael Pirnat
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
LearningTech
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
jekkilekki
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
Giordano Scalzo
 
Clean code with google guava jee conf
Clean code with google guava jee confClean code with google guava jee conf
Clean code with google guava jee conf
Igor Anishchenko
 
Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
Christine Cheung
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
Reem Alattas
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
Dragos Ionita
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
Manoj Kumar
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1
Robert Pearce
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
Leo Hernandez
 
Swift 2
Swift 2Swift 2
Swift 2
Jens Ravens
 
Google Guava
Google GuavaGoogle Guava
Google Guava
Scott Leberknight
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
Derek Brown
 

What's hot (20)

What are arrays in java script
What are arrays in java scriptWhat are arrays in java script
What are arrays in java script
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
JavaScript 1 for high school
JavaScript 1 for high schoolJavaScript 1 for high school
JavaScript 1 for high school
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Clean code with google guava jee conf
Clean code with google guava jee confClean code with google guava jee conf
Clean code with google guava jee conf
 
Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
Swift 2
Swift 2Swift 2
Swift 2
 
Google Guava
Google GuavaGoogle Guava
Google Guava
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 

Viewers also liked

Top 10 WordPress Logo Showcase Plugins 2016
Top 10 WordPress Logo Showcase Plugins 2016Top 10 WordPress Logo Showcase Plugins 2016
Top 10 WordPress Logo Showcase Plugins 2016
Michael Wood
 
WordPress or Drupal : Which is better ?
WordPress or  Drupal :  Which is better ?WordPress or  Drupal :  Which is better ?
WordPress or Drupal : Which is better ?
Michael Wood
 
Effective logo slider plugins are here
Effective  logo slider plugins are hereEffective  logo slider plugins are here
Effective logo slider plugins are here
Michael Wood
 
野菜でつながる学菜Project第6回ミーティング
野菜でつながる学菜Project第6回ミーティング野菜でつながる学菜Project第6回ミーティング
野菜でつながる学菜Project第6回ミーティング
SHINLINE Co., Ltd.
 
Boletín 30/01/2017
Boletín 30/01/2017Boletín 30/01/2017
Boletín 30/01/2017
Openbank
 
150622 教育評価論 第10講(課題解決評価)
150622 教育評価論 第10講(課題解決評価)150622 教育評価論 第10講(課題解決評価)
150622 教育評価論 第10講(課題解決評価)
Koyo Yamamori
 
Šéf robot naša budúcnosť
Šéf robot naša budúcnosťŠéf robot naša budúcnosť
Šéf robot naša budúcnosť
Peter Ulcin
 
Keri Jaehnig - Graphic Resume
Keri Jaehnig - Graphic ResumeKeri Jaehnig - Graphic Resume
Keri Jaehnig - Graphic Resume
Idea Girl Media | Social Media Marketing
 
Otrova Gomas - El jardín de los inventos
Otrova Gomas - El jardín de los inventos   Otrova Gomas - El jardín de los inventos
Otrova Gomas - El jardín de los inventos
Miguel Angel
 
Aseguramiento de la calidad en el soldeo por Resistencia (02/17)
Aseguramiento de la calidad en el soldeo por Resistencia (02/17)Aseguramiento de la calidad en el soldeo por Resistencia (02/17)
Aseguramiento de la calidad en el soldeo por Resistencia (02/17)
ITCS - Institut Tècnic Català de la Soldadura
 
БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7
БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7
БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7
Елена Овечкина
 
Otrova Gomas - El hombre más malo del mundo
Otrova Gomas - El hombre más malo del mundo   Otrova Gomas - El hombre más malo del mundo
Otrova Gomas - El hombre más malo del mundo
Miguel Angel
 
13. sürrealism
13. sürrealism13. sürrealism
13. sürrealism
Merille Hommik
 

Viewers also liked (14)

Top 10 WordPress Logo Showcase Plugins 2016
Top 10 WordPress Logo Showcase Plugins 2016Top 10 WordPress Logo Showcase Plugins 2016
Top 10 WordPress Logo Showcase Plugins 2016
 
講演資料|生活者視点が鍵となるオウンドメディアマーケティング
講演資料|生活者視点が鍵となるオウンドメディアマーケティング講演資料|生活者視点が鍵となるオウンドメディアマーケティング
講演資料|生活者視点が鍵となるオウンドメディアマーケティング
 
WordPress or Drupal : Which is better ?
WordPress or  Drupal :  Which is better ?WordPress or  Drupal :  Which is better ?
WordPress or Drupal : Which is better ?
 
Effective logo slider plugins are here
Effective  logo slider plugins are hereEffective  logo slider plugins are here
Effective logo slider plugins are here
 
野菜でつながる学菜Project第6回ミーティング
野菜でつながる学菜Project第6回ミーティング野菜でつながる学菜Project第6回ミーティング
野菜でつながる学菜Project第6回ミーティング
 
Boletín 30/01/2017
Boletín 30/01/2017Boletín 30/01/2017
Boletín 30/01/2017
 
150622 教育評価論 第10講(課題解決評価)
150622 教育評価論 第10講(課題解決評価)150622 教育評価論 第10講(課題解決評価)
150622 教育評価論 第10講(課題解決評価)
 
Šéf robot naša budúcnosť
Šéf robot naša budúcnosťŠéf robot naša budúcnosť
Šéf robot naša budúcnosť
 
Keri Jaehnig - Graphic Resume
Keri Jaehnig - Graphic ResumeKeri Jaehnig - Graphic Resume
Keri Jaehnig - Graphic Resume
 
Otrova Gomas - El jardín de los inventos
Otrova Gomas - El jardín de los inventos   Otrova Gomas - El jardín de los inventos
Otrova Gomas - El jardín de los inventos
 
Aseguramiento de la calidad en el soldeo por Resistencia (02/17)
Aseguramiento de la calidad en el soldeo por Resistencia (02/17)Aseguramiento de la calidad en el soldeo por Resistencia (02/17)
Aseguramiento de la calidad en el soldeo por Resistencia (02/17)
 
БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7
БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7
БЮЛЛЕТЕНЬ НАУКИ И ПРАКТИКИ (BULLETIN OF SCIENCE AND PRACTICE) № 7
 
Otrova Gomas - El hombre más malo del mundo
Otrova Gomas - El hombre más malo del mundo   Otrova Gomas - El hombre más malo del mundo
Otrova Gomas - El hombre más malo del mundo
 
13. sürrealism
13. sürrealism13. sürrealism
13. sürrealism
 

Similar to Stuff you didn't know about action script

Js types
Js typesJs types
Js types
LearningTech
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
AndreCharland
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
Solv AS
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
Christoffer Noring
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
Stijn Van Minnebruggen
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
Juergen Fesslmeier
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: Intro
Adam Crabtree
 
Js hacks
Js hacksJs hacks
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
Arthur Puthin
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 
Java script
Java scriptJava script
Java script
Adrian Caetano
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
Denis Ristic
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
William Myers
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
RameshNair6
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
Anıl Sözeri
 

Similar to Stuff you didn't know about action script (20)

Js types
Js typesJs types
Js types
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Javascript
JavascriptJavascript
Javascript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: Intro
 
Js hacks
Js hacksJs hacks
Js hacks
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Java script
Java scriptJava script
Java script
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 

More from Christophe Herreman

De kathedraal en de bazaar
De kathedraal en de bazaarDe kathedraal en de bazaar
De kathedraal en de bazaar
Christophe Herreman
 
How to build an AOP framework in ActionScript
How to build an AOP framework in ActionScriptHow to build an AOP framework in ActionScript
How to build an AOP framework in ActionScript
Christophe Herreman
 
GradleFX
GradleFXGradleFX
AS3Commons Introduction
AS3Commons IntroductionAS3Commons Introduction
AS3Commons Introduction
Christophe Herreman
 
Spring Actionscript at Devoxx
Spring Actionscript at DevoxxSpring Actionscript at Devoxx
Spring Actionscript at Devoxx
Christophe Herreman
 
Spring ActionScript
Spring ActionScriptSpring ActionScript
Spring ActionScript
Christophe Herreman
 
The Prana IoC Container
The Prana IoC ContainerThe Prana IoC Container
The Prana IoC Container
Christophe Herreman
 

More from Christophe Herreman (7)

De kathedraal en de bazaar
De kathedraal en de bazaarDe kathedraal en de bazaar
De kathedraal en de bazaar
 
How to build an AOP framework in ActionScript
How to build an AOP framework in ActionScriptHow to build an AOP framework in ActionScript
How to build an AOP framework in ActionScript
 
GradleFX
GradleFXGradleFX
GradleFX
 
AS3Commons Introduction
AS3Commons IntroductionAS3Commons Introduction
AS3Commons Introduction
 
Spring Actionscript at Devoxx
Spring Actionscript at DevoxxSpring Actionscript at Devoxx
Spring Actionscript at Devoxx
 
Spring ActionScript
Spring ActionScriptSpring ActionScript
Spring ActionScript
 
The Prana IoC Container
The Prana IoC ContainerThe Prana IoC Container
The Prana IoC Container
 

Recently uploaded

"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes..."Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
Anant Gupta
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
Neo4j
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
kumarjarun2010
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
digitalxplive
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
sunilverma7884
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
313mohammedarshad
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
Priyanka Aash
 
Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
Safe Software
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
moinahousna
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Networks
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
maigasapphire
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
bhumivarma35300
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
HackersList
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python CodebaseEuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
CEPTES Software Inc
 

Recently uploaded (20)

"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes..."Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
 
Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python CodebaseEuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
 

Stuff you didn't know about action script

  • 1. Stuff You Didn't Know About ActionScript Christophe Herreman @herrodius
  • 2. ... or an exploration of the ActionScript 3 language in which you might discover new things that you were not aware of and that one day might come in handy, or in which you will want to scream out WTF's so loud that the whole venue might think I'm presenting naked whilst in reality you are just looking at a piece of ActionScript code that is so counter- intuitive or looks rather puzzling you wonder how anyone came up with the idea to implement certain parts of the API this way, which on the other hand makes the language also very fun to work with once you know how to deal with these peculiarities and it becomes clear that ActionScript is actually pretty cool and powerful ...
  • 3. About me Run Stack & Heap, a development, consulting and training company based in Belgium specializing in Web / RIA Development Certified expert Flex with AIR, loved Flash since 1999 Founder of Spring ActionScript and AS3Commons Apache Flex committer
  • 5. Equality "==" Checks if 2 values are equal, and applies data conversion if the values have different data types. "hello" == "hello" // true "5" == 5 // true true == 1 // true false == 0 // true "true" == true // false null == undefined // true
  • 6. Strict Equality "===" Checks if 2 values and their types are equal. "hello" === "hello" // true "5" === 5 // compile error true === 1 // false false === 0 // false "true" === true // false null === undefined // false
  • 7. Equality "==" Complex data types are compared by reference, not value. var a:Array = [1, 2, 3]; var b:Array = [1, 2, 3]; a == b // false var c:Array = a; a == c // true
  • 8. Conditional "?:" Known as the Ternary Operator. var result:Boolean = (a > b) ? x : y; // shorthand for var result:Boolean; if (a > b) { result = x; } else { result = y; }
  • 9. Logical OR "||=" function (a:Object) { a ||= new Object(); } // shorthand for function (a:Object) { if (a === null) { a = new Object(); } }
  • 10. Logical AND "&&=" function toHTMLTag (s:String) { s &&= "<" + s + ">"; return s; } // shorthand for function toHTMLTag (s:String) { if (s !== null && (s.length > 0)) s = "<" + s + ">"; return s; }
  • 11. "as" Casts a value to another data type, returning null if the cast fails. "hello" as String // "hello" 5 as String // null true as MyClass // null String("hello") // "hello" String(5) // "5" MyClass(true) // Runtime Error
  • 12. "is" vs "instanceof" Check if a value is of a certain data type. var s:Sprite = new Sprite(); s is Sprite // true s is DisplayObject // true s is IEventDispatcher // true s instanceof Sprite // true s instanceof DisplayObject // true s instanceof IEventDispatcher // false
  • 13. "::" name qualifier Identifies the namespace of an object. public namespace Dutch; public namespace French; Dutch function hello():String { return "hallo"; } French function hello():String { return "bonjour"; }
  • 14. "::" name qualifier Dutch::hello() // "hallo" French::hello() // "bonjour"
  • 15. "::" name qualifier "public", "private", "protected", "internal" are also namespaces. public function get a():String; private function set a(value:String); trace(a) // compile error a = "hello" // compile error trace(public::a) private::a = "hello"
  • 16. "in" vs Object.hasOwnProperty Check if an object contains a certain property. "CASEINSENSITIVE" in Array // true "CASEINSENSITIVE" in [] // false "length" in Array // true "length" in [] // true [].hasOwnProperty("CASEINSENSITIVE") // false [].hasOwnProperty("length") // true
  • 17. "arguments" An array available in each function that contains the arguments passed to the function. function myFunction (x:int) { for(var i:uint=0; i<arguments.length; i++){ trace(arguments[i]); } } myFunction(1, 2, 3); // 1 // 2 // 3
  • 18. "..." Rest Arguments Pass an arbitrary number of extra arguments to a function. function myFunction (x:int, ... rest) { for (var i:uint = 0; i< rest.length; i++) { trace(rest[i]); } } myFunction(1, 2, 3); // 2 // 3
  • 20. Object creation var a:Array = new Array(); var a:Array = []; // faster var o:Object = new Object(); var o:Object = {}; // faster var v:Vector.<String> = new Vector.<String>(); v.push("a"); v.push("b"); var v:Vector.<String> = new <String>["a", "b"];
  • 21. Object References var a:Object = {}; a.name = "John"; var b:Object = a; b.name = "Elvis"; trace(a.name); // output "Elvis"
  • 22. Object Copies Create deep or shallow copies depending on the scenario. // deep copy private function clone(obj:Object):Object { var bytes:ByteArray = new ByteArray(); bytes.writeObject(obj); bytes.position = 0; return bytes.readObject(); }
  • 23. Events Always override the "clone" method in an Event subclass. Prevents runtime type coercion errors when redispatching. class MyEvent extends Event { public function MyEvent(data:Object){ _data = data; } override public function clone():Event { return new MyEvent(_data); } }
  • 24. for...in vs. for each...in var arr:Array = ["a", "b", "c"]; // loops through keys (0, 1, 2) for ( var i in arr ) { trace( i ); } // loop through values ("a", "b", "c") for each ( var s:String in arr ) { trace( s ); } Gotcha: order is not guaranteed, use for loop with counter
  • 25. trace() You can pass multiple arguments to the trace() method. No need to compose a string. trace(new Date(2012, 4, 22), "Aloha", Math.PI, true); // Tue May 22 00:00:00 GMT+0200 2012 Aloha 3.141592653589793 true
  • 26. Labeled Loops Use "label" on a loop to name it. Useful when breaking from nested loops. mainLoop: for (var i:uint = 0; i<10; i++) { for (var j:uint = 0; j<10; j++) { if (i == 5 && j == 7) { break mainLoop; } } }
  • 27. Global Functions Declare a single function in an *.as file and name the file the same as the function. // in file: myGlobalFunction.as package { function myGlobalFunction():void { trace("in myGlobalFunction"); } }
  • 28. Adding Methods to Built-in Classes Extend the behavior of built-in classes by adding methods to the prototype. Array.prototype.removeItem = function (item:*):void { var index:int = this.indexOf(item); if (index > -1) { this.splice(index, 1); } }; var a:Array = [1, 2, 3]; a.removeItem(2); trace(a); // 1, 3
  • 29. Gotchas & WTF's
  • 30. Casting var o:MyObject = new MyObject(); var o1:MyObject = MyObject(o); var o2:MyObject = o as MyObject; // o1 === o2 var a:Array = [1, 2, 3]; var a1:Array = Array(a); // new Array !!! var a2:Array = a as Array; // a1 !== a2 Also the case with Date and Error classes. Watch out!
  • 31. Casting to Boolean Boolean(true) // true Boolean(false) // false Boolean(0) // false Boolean(1) // true Boolean(-1) // true Boolean("true") // true Boolean("false") // true Boolean("") // false Boolean(" ") // true Boolean("0") // true Boolean("1") // true Boolean(null) // false Boolean(undefined) // false Boolean(Object) // true Boolean({}) // true
  • 32. Array class var a:Array = new Array(); // empty array var a:Array = []; // empty array var a:Array = new Array(10); // array with length 10 var a:Array = [10]; // array with 1 element: 10 var a:Array = new Array(1, 2, 3); // array with values 1, 2, 3 var a:Array = [1, 2, 3]; // array with values 1, 2, 3
  • 33. Date class new Date(); // current date new Date(2012); // 01/01/1970 01:00: 02 new Date(2012, 1); // 01/02/2012 00:00:00 new Date(2012, 1, 1); // 01/02/2012 00:00:00 public function Date( yearOrTimevalue:Object, month:Number, // 0 to 11 date:Number = 1, // 1 to 31 hour:Number = 0, // 0 to 23 minute:Number = 0, // 0 to 59 second:Number = 0, // 0 to 59 millisecond:Number = 0) // 0 to 999
  • 34. Throwing Parties You can throw more than just errors. class AwesomeParty {} try { throw new AwesomeParty(); } catch (party:AwesomeParty) { // go loose at moNo! } Practical use?
  • 35. More info ActionScript 3 Language Reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/ ActionScript 3 Language Specification http://livedocs.adobe.com/specs/actionscript/3/ Twitter @herrodius, @stackandheap Stack & Heap Labs http://labs.stackandheap.com