dcsimg
A Flash Developer Resource Site

Results 1 to 13 of 13
  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    9

    to learn as2 or as3 - please advice

    Hello everybody,

    I'm really bad on ActionScript, but now I decided to make it my top priority and to learn it. I'm a little bit confused though - should I learn as2 or as3?!?

    Any advice will be appreciated.

    p.s.: I'm posting this request in both as2 and as3 forums.
    Sorry if this is wrong in some way, I'm new to flashkit too

  2. #2
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    hi and welcome

    go 3 for sure, it's superior in every way and way different than all earlier versions so if you went v2 instead you'd basically have to start from scratch to go 3 later.
    Evolve Designs Interactive Media
    the natural selection

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    156
    whats the main diff

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    whats the main diff
    http://gskinner.com/talks/as3workshop/

    gparis

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i resisted AS3 for a long time, until finally i had to (a customer had an existing project in 3). i've spent about 6 months now exclusively in 3, and am now more comfortable with it than 2. it has some very attractive advantages:

    1. regular expressions
    2. robust bitmap support, incl. dynamic bitmaps
    3. photoshop-esque features such as blendMode
    4. speed. in every operation i've tried (a lot), 3's faster than 2, often more than twice as fast - adobe claims 10x in certain situations (which i don't doubt), but this is a little misleading i think - code execution is FAST - and the new VM is undeniably a lot faster, but when the difference 250ms versus 500ms, it sounds significant but the net savings is a quarter of a second (virtually imperceptible).

    however, 2 has a couple things i really miss, specifically:

    1. ability to extend Functions (via prototyping), which is impossible in 3 (if i'm wrong about this, i'd be happy to find that out)
    2. addProperty as an in-line feature (you can recreate a lot of the same functionality in 3 using subclasses, but it's nice being able to perform this kind of thing dynamically once in a while)
    3. similiarity to javascript. my old AS2 lib worked just as well in a .js as a .as

    there are lots of other little things too; i miss the textfield.variable property from 2, and i hate how looping over Object produces random iterations. on the other hand, i really like some of the new built-in array and string methods like filter and forEach, as well as the for..each loop.

  6. #6
    Senior Member pixelpusher84's Avatar
    Join Date
    May 2004
    Posts
    186
    AS3 all the way AS2 is dead.

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    156
    Thanks paris, I am reading through that now. How would you do simple things like

    PHP Code:
    button1.onPress = function() {
    _root.gotoAndPlay(2);

    in as3?

  8. #8
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,708
    I have NO experience with AS3.. and have avoided it liek the plague.. but even I say AS3..

    if your at total beginning.. there is NO DOUBT AS3 is the way (IMHO)

    I just never really got into external classes...or making my own custom classes unfortunately..so the whole IMPORT ever class for everything little thing in AS3 was a huge turn off for me.. but I guess every NEW thing has its learning curve..

  9. #9
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Quote Originally Posted by moagrius
    2. robust bitmap support, incl. dynamic bitmaps
    3. photoshop-esque features such as blendMode
    Both of these are available in AS2 (they were new features in Flash 8).

    Quote Originally Posted by moagrius
    1. ability to extend Functions (via prototyping), which is impossible in 3 (if i'm wrong about this, i'd be happy to find that out)
    The prototype object is also still available in AS3.
    http://www.kirupa.com/forum/showthread.php?p=1894555

    Quote Originally Posted by moagrius
    3. similiarity to javascript. my old AS2 lib worked just as well in a .js as a .as
    ActionScript 3 is still similar to ActionScript - still based on the ECMAScript spec. I can't think of anything in particular in AS3 that takes it further from JavaScript. In fact the inclusion of regex gets it closer. If you know of something that makes it less like JavaScript, I'd be interested to hear it.

  10. #10
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    Quote Originally Posted by senocular
    The prototype object is also still available in AS3.
    it's still available but drastically changed. first, if you just fill the frame with whatever.prototype.somemethod = function(arg){};somethingelse.prototoype.anotherme thod = function(arg){}; you get namespace conflicts for argument labels. afaik, you have to declare it as a named function, then assign it to the prototype. also, as far as i can tell, you can't prototype Function at all. my favorite method was
    PHP Code:
    _global["Function"].prototype.bind = function(){
        var 
    method thisparameters arguments;
        return function () {
            return 
    method.apply(thisparameters.concat(arguments));
        };
    }; 
    that can be closely emulated with something like
    PHP Code:
    function bind(method,...args){
        return function(...
    rest){
            return 
    method.apply(this,args.concat(rest));
        }
    }; 
    but the scope of "this" being lost using event listeners, and having the arguments count checked, makes it a lot less useful.
    Quote Originally Posted by senocular
    ActionScript 3 is still similar to ActionScript - still based on the ECMAScript spec. I can't think of anything in particular in AS3 that takes it further from JavaScript. In fact the inclusion of regex gets it closer. If you know of something that makes it less like JavaScript, I'd be interested to hear it.
    a few things i've noticed:
    - the namespace conflicts for argument labels in unnamed functions
    - classes
    - inability to extend the Function class whatsoever
    - the scope of "this" (in JS, if you have someObject.someMethod = function(){return this;} and you call someObject.someMethod from another object, "this" is the second calling object - in AS3 it's someObject)
    - random object iteration. in js, it's predictable and manageable, in AS3 it's not.
    - forced use of event listeners as opposed to onclick, onmouseover, etc (which i realize can be somewhat approximated with dynamic classes) - but also creates some ambiguity when trying to overwrite. in AS3 you can't overwrite an unreferenced listener function. e.g., you have a hundred elements that all have different listener functions for click; if you want to change a particular elements click behavior you have to remove it explicitly and add the new behavior explicitly, rather than just onclick = new func;.

    i'm not trying to debate whether 2's better or worse then 3 - i personally use 3 exclusively now - i'm just saying that a year ago, i could take all the protos and procedures i used in AS2 and cut and paste them exactly into a JS file and everything worked fine. that's not the case now. finally, thanks for the heads up on the blendmode and bitmap availability in 8 - i didn't know that.
    Last edited by moagrius; 07-13-2008 at 05:12 PM.

  11. #11
    Junior Member
    Join Date
    Jun 2008
    Posts
    9
    Thank you all.

    I think I'm going on 3 now

  12. #12
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    I am not familiar with the namespace conflict, and could not reproduce it given your examples

    Classes could probably be considered an optional extra feature of ActionScript and don't necessarily take away from its similarities with JavaScript (but are a part of JS2 in behave similarly in that sense)

    Save for the use of ...rest, your first bind method works for me in AS3

    I think your 'this' example is incorrect. It occurs for named functions, not anonymous functions. You can still move those around and see a change in the value of 'this'

    Iteration is also not random. Sealed class members are hidden from iteration. Only dynamic members are visible (though can be changed via setPropertyIsEnumerable())

    The DOM 2 spec uses addEventListener just like ActionScript, so that's really no different either. Callbacks are still possible depending on the environment/API you're working with.

    But in your discussion you bring up a couple of good differences. Method closures for named functions and the ...rest parameter (not having an arbitrary number of arguments possible by default). Overall, though, I don't think they're huge deterrents in having portable code.

  13. #13
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    hopefully i'm just not understanding something, and if you can get the bind method to work - or for that matter, ANY extension of Function itself - i'd love to hear how.

    this worked in AS2
    PHP Code:
    _global["Function"].prototype.bind = function(){ 
        var 
    method thisparameters arguments
        return function () { 
            return 
    method.apply(thisparameters.concat(arguments)); 
        }; 
    }; 
    // and an e.g.
    function test(a,b,c){
        return 
    c;
    };

    var 
    example test.bind(10);

    trace(example(1,100)); 
    and the JS version was able to reference Function directly, but had to be amended to account for the fact that arguments in JS are a collection and don't have array methods attached (and as you know arguments are a full-fledged array object in AS), so they have to be force fed
    PHP Code:
    Function.prototype.bind = function(){
        var 
    a=[],b=arguments.length,c=this;
        while(
    b)a[--b]=arguments[b];
        return function(){
            var 
    b=arguments.length;
            while(
    b)a.push(arguments[--b]);
            return 
    c.apply(this,a);
        };
    };
    // same e.g.,
    function test(a,b,c){
        return 
    c;
    };

    var 
    example test.bind(10);

    alert(example(1,100)); 
    in AS3, _global's gone, so replacing it with
    PHP Code:
    Function.prototype.bind =  function(){
        var 
    method thisargs arguments;
        return function(){ 
            return 
    method.apply(this,args.concat(arguments)); 
        } 
    }; 

    function 
    test(a,b,c){
        return 
    c;
    };

    var 
    example test.bind(10);

    trace(example(1,100)); 
    produces
    PHP Code:
    1061Call to a possibly undefined method bind through a reference with static type Function. 
    which AFAIK means Function can't be extended in any fashion. is that incorrect?

    as far as the namespace conflict:
    PHP Code:
    Array.prototype.add = function(a){if(!this.test(a))this.push(a);};
    Array.
    prototype.values = function(a){var b=this.length,c=[];while(b)c[--b]=this[b][a];return c;};
    Array.
    prototype.test = function(a){var b=this.length;while(b)if(this[--b]==a)return true;return false;};
    Array.
    prototype.cull = function(){var a=this.length;while(a)if(!this[--a])this.splice(a,1);return this;};
    Array.
    prototype.unique = function(){var a={},b=[],c=this.length,d;while(c)a[this[--c]]=null;for(d in a)b.push(c);return b;};
    Array.
    prototype.each = function(a){var b=[],c=this.length;while(c)b[--c]=a.call(this[c]);return b;};
    Array.
    prototype.match = function(a){var b=[],c=this.length,d;while(c--)for(d in a)if(this[c][d]==a[d])b.push(this[c]);return b;}; 
    produces
    PHP Code:
    **Error** Scene 1Layer 'Layer 1'Frame 1Line 31151A conflict exists with definition b in namespace internal.
         Array.
    prototype.test = function(a){var b=this.length;while(b)if(this[--b]==a)return true;return false;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 51151A conflict exists with definition a in namespace internal.
         Array.
    prototype.unique = function(){var a={},b=[],c=this.length,d;while(c)a[this[--c]]=null;for(d in a)b.push(c);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 51151A conflict exists with definition b in namespace internal.
         Array.
    prototype.unique = function(){var a={},b=[],c=this.length,d;while(c)a[this[--c]]=null;for(d in a)b.push(c);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 51151A conflict exists with definition c in namespace internal.
         Array.
    prototype.unique = function(){var a={},b=[],c=this.length,d;while(c)a[this[--c]]=null;for(d in a)b.push(c);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 61151A conflict exists with definition b in namespace internal.
         Array.
    prototype.each = function(a){var b=[],c=this.length;while(c)b[--c]=a.call(this[c]);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 61151A conflict exists with definition c in namespace internal.
         Array.
    prototype.each = function(a){var b=[],c=this.length;while(c)b[--c]=a.call(this[c]);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 71151A conflict exists with definition d in namespace internal.
         Array.
    prototype.match = function(a){var b=[],c=this.length,d;while(c--)for(d in a)if(this[c][d]==a[d])b.push(this[c]);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 71151A conflict exists with definition b in namespace internal.
         Array.
    prototype.match = function(a){var b=[],c=this.length,d;while(c--)for(d in a)if(this[c][d]==a[d])b.push(this[c]);return b;};

    **
    Error** Scene 1Layer 'Layer 1'Frame 1Line 71151A conflict exists with definition c in namespace internal.
         Array.
    prototype.match = function(a){var b=[],c=this.length,d;while(c--)for(d in a)if(this[c][d]==a[d])b.push(this[c]);return b;};

    Total ActionScript Errors9,  Reported Errors
    object iteration isn't technically random (meaning, a particular object will always loop in whatever order), but it's not predictable or manageable. in JS, the object iterates in order the properties were assigned; if assigned using an object literal it reads right to left
    PHP Code:
    window.onload = function(){
        var 
    obj = {name:"moagrius",age:33,gender:"male",smoker:true};
        for(var 
    each in obj){
            var 
    textbox document.createElement("div");
            
    textbox.innerHTML each ":" obj[each];
            
    document.body.appendChild(textbox);
        }
    }
    //name,age,gender,smoker 
    in AS2
    PHP Code:
    var obj = {name:"moagrius",age:33,gender:"male",smoker:true};

    var 
    holder this.createEmptyMovieClip(0,0);
    for(var 
    each in obj){
        var 
    depth holder.getNextHighestDepth();
        var 
    textbox holder.createTextField(depth,depth,0,holder._height,100,20);
        
    textbox.text each ":" obj[each];
    };
    //name,age,gender,smoker 
    in AS3, it jumps all over the place
    PHP Code:
    var obj = {name:"moagrius",age:33,gender:"male",smoker:true};

    var 
    holder = new Sprite();

    for(var 
    each in obj){
        var 
    textbox = new TextField();
        
    textbox.holder.height;
        
    textbox.height 20;
        
    textbox.text each ":" obj[each];
        
    holder.addChild(textbox);
    };

    this.addChild(holder);
    //smoker, age, gender, name - in no discernable order 
    Last edited by moagrius; 07-16-2008 at 04:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center