...these be from google reader...


Archive for the ‘AS2’ Category

Your Balls Weren’t *That* Great Anyway…

Monday, October 22nd, 2007

…confessed Serge. Unfortunately the setting was not in a specialist Amsterdam nightclub, rather, at the SAP Lounge in Brussels. After an insane month working as a consultant at thesedays, I had only one day to prepare two sessions for the Adobe
Beyond Boundaries event in Amsterdam and Brussels. My topic was “introduction to AS3 for designer types”, and as conversion bait, I did some benchmarking between flashplayer9 (as3) and fp8 (as1/2). I ran and timed some loops (files : as2 as3), with fairly predictable results. Well, I was positively surprised by 5 secs for 1 billion loops in as3 :eek:.

I also wanted to showcase the speed increases for rendering graphics. I was hellbent on creating a cheap version of the Sony Bravia Bouncing balls commercial, in as2 and 3, then woo the crowd with flashplayer9 pwning and humiliating its older counterpart. Unsurprisingly, I didn’t finish the as2 version for Amsterdam, so, during my lunch break in Brussels I hacked it together. To my disbelief they both performed more or less equally?! Right then, my moment of bewilderment was broken by the entrance of Danny Dura, “right on time” I thought to myself. Danny quickly suggested I flag useBitmapCache, and use Shapes instead of Sprites, but to no avail. At this point Serge joined the conversation, suggested I save this nutcracker for later and showcase teh 1337N355 of AS3 with the famous papervision x-wing fighter demos. This is the point where, (within the hearing distance of a number of suit&ties from some other conference) Serge announced this blogposts title :D

Joking aside, wtf? I’ve uploaded the two files, feel free to test:

AS2
AS3

(and yes, they are different files, for proof just let yourself be knocked out by the beauty of the as3 button component over it’s dinosauring sibling)

At 4000 balls, the as2 version runs at times faster than as3!!!??

Any ideas? Is it rendering? The code is pretty much identical… If you are motivated, you can even look at it:
ze zip

Oh yeah, not worth it’s own blog entry, here’s my “quick app tutorial” used in my presentations, showing some basic tasks and how they are done with AS3:

HOTT Jean Claude Dance AXXXion

Using EventDispatcher in AS2, the AS3 way

Tuesday, February 20th, 2007

After a long run of AS3 goodness, I was outsourced to do some dinosaur development at these-days… An AS2 project, which unfortunately got cancelled after just 4 days :(.

It wasn’t a total waste of time though… Coming back from ActionScript3 to 2 brought along a number of “better” programming practices :)

The best example that popped up is event handling… Sure, event bubbling etc. is out of the question, but some basics can be imitated with relatively nice results.

In AS3, you extend mx.events.EventDispatcher (or implement flash.events.IEventDispatcher) to (surprise surprise) dispatch events… The “old way” of achieving this in AS2 was to “shove in” some clunky EventDispatching code… So, simply shove that clunkiness into a class:


[as]
import mx.events.EventDispatcher;
class AS2EventDispatcher{

public function AS2EventDispatcher(){
EventDispatcher.initialize(this);
}

public function dispatchEvent(){}
public function addEventListener(){}
public function removeEventListener(){}

}
[/as]

then, (instead of typing that in each of your wanna-be dispatching classes), just like AS3, you extend it:

[as]
import AS2EventDispatcher;

class DataModel extends AS2EventDispatcher{

public function DataModel(){
super();//only drawback... in AS2 the constructor must be created and super must be invoked
}

private function dispatchSomethingSweet():Void{
dispatchEvent(new Event("something_sweet"));
}
}
[/as]

as the discerning reader would have noticed (kl3ver boy), new Event(”some_event”) is not standard AS2… so, this event class must also be created, in order to be extended:

[as]
class events.Event{

private var _type:String;
public function set type(t:String):Void{}
public function get type():String{return _type;}

private var _target:Object;
public function set target(t:Object):Void{_target=t;}
public function get target():Object{return _target;}

public function Event(t:String,targ:Object){
_type=t;
target=targ;
}

public function toString():String{
return "Event{_type:"+_type+"_target:"+_target+"}";
}

public function clone():Event{
return new Event(_type,_target);
}
}[/as]

why one might want to clone() events in as2 is beyond my willingness to think about the subject though…

anyhow, good times, good times…