Showing posts with label actionscript. Show all posts
Showing posts with label actionscript. Show all posts

Thursday, July 2, 2009

X is for XML in ActionScript

ActionScript's powerful XML support is based on E4X. E4X stands for ECMAScript for XML and is a Document Object Model (DOM) interface for XML. E4X makes XML a first-class citizen in ActionScript.

Learn more about ActionScript XML in Flex at Flex After Dark...

Thursday, June 11, 2009

T is for Timer

The Timer is a utility class in the flash.utils package. A timer's job is to fire off events at specified intervals.

The below ActionScript shows how to create a Timer instance and start it.

   import flash.utils.Timer;
import flash.events.TimerEvent;

// create a timer which fires every second (1000 ms)
var timer:Timer = new Timer( 1000 );

// add a listener to the timer
timer.addEventListener( TimerEvent.TIMER, handleTimerEvent );

// start the timer
timer.start();

Learn more about the ActionScript Timer at Flex After Dark...

Sunday, April 5, 2009

J is for Java (vs ActionScript)

ActionScript and Java are both powerful, object-oriented languages with many similarities.

Both Java and ActionScript:

  • Are object-oriented
  • Use single inheritance
  • Have a base Object class (which is automatically sub-classed)
  • Use strongly typed variables
  • Have Packages, Classes, and Interfaces
  • Support public, protected, and private methods and variables
  • Support static functions and variables
  • Support try/catch/finally exception handling

There are also many differences between ActionScript and Java.

Important differences between Java and ActionScript:

  • ActionScript has get/set functions
  • ActionScript supports dynamic classes
  • ActionScript supports closure functions
  • ActionScript supports optional function arguments, but does not support overloading
  • ActionScript does not allow private classes or constructors
Learn more about the ActionScript language, and it's similarities and differences to Java, at Flex After Dark...

Sunday, March 29, 2009

H is for HTTPService

Flex's HTTPService is used to make HTTP requests and handle the results. When you call the HTTPService object's send() method, it makes an HTTP request to the specified URL, and an HTTP response is returned (asynchrnously).

The HTTPService is part of Flex's Remoting/RPC library.

Making an HTTP request in ActionScript:

  1. Create an instance of mx.rpc.http.HttpService
  2. Set the HTTP url
  3. Set the result format
  4. Send a request
  5. Handle the result or fault
    1. via pre-registered event listeners
    2. or via responders
Learn more about the Flex HTTPService at Flex After Dark...

Wednesday, March 25, 2009

G is for Get/Set Functions

In a lot of programming languages we're use to seeing "getter and setter" functions "wrapped" around private properties. The idea is to encapsulate the access of variables behind these "accessor" functions.

You won't see nearly as many getter/setter functions in ActionScript. It's not because of laziness or "bad OOP". It is because ActionScript has support for special get and set functions that can encapsulate property access behind function calls, but without changing the property access syntax.

public class Person
{
private var _name:String;

public function get name():String
{
return this.name;
}

public function set name( value:String ):void
{
this.name = value;
}
}
Learn more about ActionScript Get/Set Functions at Flex After Dark...

Friday, March 20, 2009

E is for E4X

E4X stands for ECMAScript for XML. (Remember that ActionScript is ECMAScript.)

E4X makes XML a first-class citizen in ActionScript.

   var xmlAlbum:XML =
<album name="Sky Blue Sky" artist="Wilco">
<tracks>
<track name="Either Way" seconds="187"/>
<track name="You Are My Face" seconds="278"/>
<track name="Impossible Germany" seconds="358"/>
<track name="Sky Blue Sky" seconds="203"/>
<track name="Side With The Seeds" seconds="256"/>
<track name="Shake It Off" seconds="342"/>
<track name="Please Be Patient With Me" seconds="199"/>
<track name="Hate It Here" seconds="273"/>
<track name="Leave Me (Like You Found Me)" seconds=""/>
<track name="Walken" seconds="267"/>
<track name="What Light" seconds="216"/>
<track name="On And On And On" seconds=""/>
</tracks>

Notice in the example that you are not wrapping the XML in quotes or treating it as a string. Just type the XML as a literal.

Learn more about Flex and ActionScript support for XML via E4X at Flex After Dark...

Wednesday, March 18, 2009

D is for Dynamic Classes

ActionScript allows classes to be defined as dynamic. A dynamic class can have public properties and functions attached to it at runtime.
   public dynamic class DynamicClass
{
public DynamicClass()
{

}
}
Note the dynamic keyword used in the class declaration. So even though DynamicClass has not properties or functions defined (besides those of its super-class, Object), we can still attach properties and functions to it dynamically.

Learn more about ActionScript Dyanmic Classes at Flex After Dark...

Saturday, March 14, 2009

A is for ActionScript

ActionScript is the language of Flex (and Flash). ActionScript is Adobe's implementation of ECMA Script, thus is similar in many ways to JavaScript.

Characteristics of ActionScript:

  • Is object oriented
  • Uses single inheritance
  • Uses strongly typed variables
  • Has Packages, Classes, and Interfaces
  • Supports static functions and variables
  • Supports dynamic classes and objects
ActionScript related links: