TracNav
AS2 Standard...
- Downloads
- Installation
- Release Notes
- View Source
- Discussion
- Unit Tests
Project Owner...
- Pedr Browne
Demos...
FlashLite...
- Balloonatroid
PureMVC Standard for AS2
Release Notes
This release is compatible with the AS3 Reference implementation version 2.0.1.
Writing PureMVC-based Applications in AS2
The simple language caveats:
| AS3 | AS2 |
| void | Void |
| const | var |
| addEventListener | addListener |
| a = b as MyClass | a = MyClass(b) |
| protected | public |
| override | n/a |
FlashLite Implementation Notes
- Don't use fscommand2 in the constructor of a Mediator. will work in the phone but it will transform the object in a very strange and unregisterable way inside the Flash 9 player.
- Events are not the same as in Flash 9. flash.events.Event does not exist. Events are far more rudimentary. Because the way they are handled is by setting a function onto a MovieClip, which will execute in the context of that MovieClip, it is difficult for a MovieClip to communicate out-bound to its
Mediator.
- A Delegate class similar to mx.controls.Delegate is used to add the Mediator's methods as the listener methods on a stewarded MovieClip, and have those methods called from the context of the Mediator and not the clip. Arguments can be passed.
AS3 vs AS2 Implementation Notes
COMMANDS
Aside from obvious language differences, the only major difference between the two versions involves Commands. AS3 introduced the ability to create a class from a class reference (in the form of a String) using:
eg.
var myClassref:String = "com.mysite.myclasses.MyClass"
var myInstance : IMyClass = new myClassRef();
This functionality does not exist in AS2, so we pass-in and re-use an instance of an ICommand instead of a class reference. This Means that when you register a Command, you use:
eg.
registerCommand(STARTUP, new StartupCommand());
The resultant functionality is essentially the same, with one important stipulation. Commands must be stateless as they will potentially be reused.
ARRAYS
It is also worth noting that you cannot cast to Arrays in AS2. This can cause problems in Proxies when using a getter to cast 'data' to its correct datatype. One solution is to use:
eg.
var myArray:Array = {a:data}.a
This will allow you to return myArray out of your getter without throwing an error by adding then accessing data from a temporary object, negating type checking.
INTERFACES
In AS3 interfaces are inherited, but in AS2, they are not.
In AS3, an interface is inherited by subclasses. If a superclass implements an interface, classes that subclass it will also implement that interface without having to declare the fact explicitly and can be treated as such.
In AS2 however, subclasses need to explicitly implement an interface if they want to be treated as such, even if their superclass implements it already.
This effects any of your subclasses of Facade, Proxy, Command or Mediator, and you must ensure they explicitly implement their respective interfaces to ensure they can be used in the framework
