13 thoughts on “Must-read for AS3 developer”

  1. The very first example is wrong. The given class compiles to something like

    [AS]
    _global.A = function ()
    {
    trace(“Constructor”);
    };

    _global.A.prototype.a = 3.14;
    _global.A.prototype.b = “a string”;
    _global.A.prototype.c = -1;

    _global.A.prototype.method = function ()
    {
    trace(“A.method”);
    };
    [/AS]

  2. [OT] you formular realy SUCKS! Its the third time i write this stuff here because its empty when you go back (forgot to fill in the little calculation)

    AS2 is not transformed as Gary Grossman showed in his pdf.
    Variables initialized in the AS2 class are not initialized in the constructor, but directly in the prototype-Object (the way i wrote above).
    You can see this simply by initializing a variable with an object, then all instances of the class share the same object.
    Applying the constructor to an empty object shows this to: (A is Gary Grossman’s example class)
    [CODE]
    o = new Object();
    Function(A).apply(o);

    for (i in o) {
    trace(i + ” : ” + o[i]);
    }
    [/CODE]

  3. janosch: I may be missing the point but AVM2 is the the virtual machine for AS3 – not AS2 – so maybe that explains why you think the code is wrong?

  4. Hi,
    It says that the new garbage collection apply to AS2 script too, so simply installing the Flash 9 Plug-in resolve the cross-reference problem (for example in the XML class)?

  5. Some things are quite interesting, but others need two or three pages of explanations where only one line just names the idea.

  6. I agree with you. And I do not get a real quintessence out of it. The one real thing I get is something like every number is treated as Number. So therefore use int() while indexing arrays.

    Now have a look here. Iterating 10000000 times this is the order of fastest method first. First takes between 4.6sec and 4.8sec. The second one could be equivalent. Maybe it was a little subjectiv view here but it is not faster it seems to result more often in results like 4.9sec.
    The third is from 4.9sec to 5sec and the last about 5.2sec. But using void() is different from using our own function :o)

    void( a[int(int(j) % int(360))] );
    void( a[int(j % 360)] );
    void( a[(j % 360)|0] );
    void( a[j % 360] );

    The results are
    13.5sec for void0( a[int(j % 360)] ) and – surprise, surprise – 13.6sec for void0( a[j % 360] ).

    So this reveals for me that it should be done for hardcore optimizations but I think everyday code should use array[i] instead of casting the type correctly because of easy readability. There is no huge speed increase here.

  7. I have a very simple question.
    AS3 is faster than Java?

    In AVM2 model, JIT Compiler generate MD Code.
    Is MD Code faster than Java?

    If the answer is ‘No’, what’s the limitation of flash app?

  8. From my basic knowledge of Java without any speed-comparison-tests I would say that Java is still faster.

    I say this because as far as I know Java uses a hotspot JIT. The AVM2 is afaik not using a hotspot method if you read We make a simple “hotspot”-like decision about whether to interpret or JIT”. But Java uses different approaches of optimized machine code. For example the Math.sqrt function of Java should be much faster than the one of Flash because it uses in special cases direct CPU features. But this is only some of my basic knowledge.

    Next is about types. Using Java you can generate an array using something like int[256]. This is very bad about Flash and the AVM2 because typed arrays are still not implemented.

    The last thing I can tell is a subjective comparison. For some “research” I had to create a fluid dynamics system with user-interaction using motion-detection. You know this from setpixel.com. It was much faster using proce55ing instead of AS3 with about 30.000 particles.

  9. I’m a little late on this one, but concerning janosch’s post about AS2:

    Yes, its true that when AS2 is compiled, the AS1 equivalent is that which uses prototypes (non-static members in the class block are defined in the class prototype object). However, the example on page 4 is AS3, not AS2. Page 5 shows what the AS3 version of that class would look in AS2. That being the case, it is correct in that class variables for AS3 are not prototyped and each instance is given unique values for each definition. For that to happen in AS2, they would be defined within the constructor as indicated by page 5.

    Believe you me, if anyone knows what they’re talking about, its Gary.

Comments are closed.