Actionscript 3 code versus Actionscript 2 code

28 posts

Flag Post

I just started a class on flash programming. We didn’t really need a book for the class, but I bought an Actionscript 3.0 book. Unfortunately, the IT department didn’t upgrade flash and I was wondering I could use my 3.0 books on the 2.0 system. If not, I bet there’ll be plenty of 2.0 books on amazon’s used section :p

 
Flag Post

If you are taking AS2 in the class and using AS2, you’re going to want an AS2 book. There are some pretty substantial differences, despite many overall similarities.

 
Flag Post

Just like what arcaneCoder said. Who uses a “Learn-it-all-in-just-1-book: English” for Spanish?

 
Flag Post

Thanks. I just ordered two books off the used section.

Well, “Who uses a “Learn-it-all-in-just-1-book: English” for Spanish?” is kind of a bad example. This would be closer to using a 21st century English book from the States in 14th Century England.

 
Flag Post

2.0 is a good place to start anyway, that’s what I did… but I haven’t even gotten a 3 book yet

 
Flag Post

I agree. I found out from another thread that Kongregate is in the process of moving up to 3.0. From what I have seen, 3.0 looks a lot like JAVA so it’ll be easy for me to migrate to 3.0 (even though I know a lot more C++). So, if I want to upload any games, it’ll be nice to know until the migration. Until those used Amazon books arrive, I could probably get away with reading the 3.0 books and if I get one of those “I know how to do this in C++, how do I do it in flash” moments, I can look leaf through the 3.0 book to find what they call it in flash and google the 2.0 function.

For some reason, I kinda like the feel of Kongregate. Not too flashy and it’s a very intimate-feeling flash host with a good bottom line. Also, I’ve seen a few of the mods go “Hey, that’s a great idea. We’ll look into it!” about a random suggestion, which is a huge plus for me.

 
Flag Post

If your class is still in AS2, I suggest you don’t take it. It’s like wanting to buy an iBook G4 for the same price as a MacBook Pro.

 
Flag Post

Too late. The drop/add period is over, so if I withdraw now, it’ll be a waste of money. Also, I’m a decently strong coder overall and once I familiarize myself with the fundamentals of Actionscript, migrating to AS3 won’t be much of a problem. Besides, I have seen some pretty cool stuff done in older versions of flash.

 
Flag Post

Exactly, I don’t see the reasoning behind any notion that learning AS 2.0 is somehow going to hurt you… it can only help build a foundation for working with the newer version. IMO, as long as you’re not learning AS 1 and using onClipEvents, you’re probably doing better than a lot of people.

 
Flag Post

Yeah, plus Kongregate seems to be on Flash 8 still, so I’ll be able to post my files until they move to Flash 9. Of course if y’all have gone to Flash 9 already, feel free to correct me on this.

 
Flag Post

I’m one of the “hurry up flash 9” peeps.

AS3.0 is more alike to Javascript then it is to Java. Because they are both based on ECMAScript, which was influenced by Java. So there are some major differences you must be careful for.

Indie: I don’t really agree that learning AS2.0 will help you to work with AS3.0. They’re almost a world apart, and took me awhile to actually migrate across. I would really recommend fresh learners to jump straight to AS3.0, and save themselves the trouble of having to migrate from a less strict scripting language to the more powerful strict (and sometimes hidious) world of AS3.0.

Then again it really depends on what your aim is. If you’re one of those people who just need a play and rewind button, AS2.0 is just fine. I believe AS2.0 was created with animators in mind (during this time, games weren’t very popular), but eventually they decided that it was time to give developers a go, and produced AS3.0. So AS3.0 is for developers, AS2.0 is for animators. IMHO anyway.

 
Flag Post

So many analogies. From what everyone’s saying, I’m seeing that there’s advantages of learning both.

 
Flag Post

I’m also an experienced programmer, and trying to get into Flash I jumped right into AS 3.0 because of all the great features it had over AS 2.0.

BIG MISTAKE.

Admittedly this was nearly 6 months ago and this scene is changing daily, but what I very quickly found out was that there were no tutorials showing you how to tie things together in AS 3. There are a lot of common idioms in Flash with AS 2 that don’t work in AS 3. “Oh, I can do that effect by clicking the object and adding a Behavior… BAM! Flash stops and says ‘This is not available in AS 3.’”

You can work around it, but it’s incredibly tedious. One program I wrote to explore some bizarre optical effects, I ended up exporting my ENTIRE application to the ActionScript code, including the frames, tweens, and animations, and then attaching the objects to the graphics palette at startup. The IDE just kind of sat there, all forlorn and sulky while I did everything in text. I ended up getting so sick of it that I just walked away from all Flash development for six months, and am just now getting back into it. I have resolved to learn AS 2.0 and work in that exclusively until sufficient community support exists to leverage switching to AS 3.

ActionScript 3 is a dream to work with if you know C#, Java or C++, but if what you want to do is “sit down and crank out a Flash game”, and it’s still 2007, I’d say go with ActionScript 2.0.

/my $0.02

 
Flag Post

Chalain, I can see why, and thanks for the awesome input.

From what you are saying about C++ and Actionscript 3.0, I’ll be okay. I think I need to learn more about the GUI part of flash since I have been understanding the code without having to think too much. In fact, most of my hurdles in this class have been GUI related. The coding part has been really easy. Also, I have seen what last semester’s class did, and anything fancy will be my doing, not a requirement of the class.

 
Flag Post

nods

You definitely want to play with 2.0 at first, then. Some parts of it seem icky as I try to step back from 3.0, like a tendency/need to jam everything into the global namespace and the inability to define interfaces. But if you’ve ALSO got a little scripting or imperative programming under your belt (like perl or old-school C) I expect you’ll do just fine. Tackle the course exactly according to your plan—as an opportunity to learn the ins-and-outs of the IDE.

Of course, I am speaking from the same position of ignorance that you profess, so I do not know if my advice is any good. I’m just sayin’, if I were you, that’s how I’d do it. I’m not in a position to take a class, but I dropped $120 at the bookstore last night buying Flash 8 / AS2 books.

/my $0.02 * 6000 ;-)

 
Flag Post

I don’t really agree that learning AS2.0 will help you to work with AS3.0. They’re almost a world apart, and took me awhile to actually migrate across.

Well, okay, they are rather different, but as someone who has worked with C++ OOP, AS 2, JavaScript, Java, etc. there’s not too much different between most programming languages except syntax, and with Flash, part of making good programs is understanding the way that the Flash player works in regards to its timeline, which is pretty unique in my experience. Obviously, there’s a reason why so many people start with AS 1 or 2, because it is easier for most people to pick up (if they’re starting for the first time) than fully object-oriented, event-driven AS3. Usually you will want to learn good procedural programming skills before you dive into object-oriented.

Having said that, I look forward to working with AS 3 myself…

 
Flag Post

I believe AS2.0 was created with animators in mind (during this time, games weren’t very popular)

I don’t really think so.

 
Flag Post

Well all opinions :)

AS2.0 is a scripting language.
AS3.0 is a more powerful programming language. To call it a scripting language would be blasphemous, IMHO. :)

There are lots of reasons why AS2.0 ideologies do not work in AS3.0. Again, simply because they are just completely different things. Like learning HTML and PHP. While, having knowledge of HTML is useful, it is not essential to learning PHP. Trying to code PHP like trying to code HTML just won’t work.

Well okay, if you are just starting off into the realm of developing, AS2.0 might just be the ticket. Though I’d rather tell you to pick up a copy of basic somewhere, or get Java.

 
Flag Post

as3 is a scripting language because you don’t compile it down to assembly… also, you know its a scripting language because pretty much all the errors you get when compiling or running make sense and dont just spit out a memory address and an error code :) essentially you aren’t using a real programming language unless it seg faults on you.

 
Flag Post

fucrate: I think you’re needlessly blurring a useful distinction here. Both AS2 and AS3 compile to an intermediate format to be executed by a runtime environment, much as Java or C# do. But they’re both based off of different versions of ECMAScript, which has script right there in the freakin’ title. :-)

AS2 “feels” like a scripting language because you open up an editor and just start typing. There is an implicit global context that everything can reach through and you don’t have to set up any boilerplate—not even defining a main() function. It is very hard to paint yourself into a corner because there simply aren’t any walls. AS3 “feels” like a programming language. There are much more stringent and formal syntax requirements (and with them, powerful features). You can’t just open up an editor and type this.x = 42… now you have to declare classes and entry points.

The key distinctions between these two languages is born out by the effectiveness of the languages at various sizes. You just don’t see any 20,000-line AS2 projects out there. It’s too messy, too sloppy, too undefined. The freedom of the language causes programs to collapse under their own weight somewhere between 1,000 and 10,000 lines of code—exactly where is dependent on the expertise (and masochism, heh) of the programmer. AS3, with its much more strict requirements, looks like it will easily support programs of 50,000 to 100,000 lines of code for the same investment of of skill and experience (I base this on my own experience with comparable languages like Java, C# and Ruby). Sounds great, right? Well, you pay for it at the low end. You can give somebody a copy of Flash 8/AS2 and a 1-hour tutorial, and they’re off writing 100-line games. AS3, not so much. It lacks the same agility at the low end. This has two key drawbacks: the first and obvious one is that sitting down to “bash out a quick game” is much harder in AS3 so it doesn’t happen as often or as quickly. The second, and more sinister one, is that if you don’t already have a good head for programming, it will be much harder for you to get traction in AS3. You’ll need a 1-day training on OO programming concepts before that 1-hour tutorial will do you any good.

I’m largely conjecturing here, of course, but so far the community bears out my theory. The only people moving to AS3 right now are people who already have a strong head for programming and have a solid background in AS2 development. If you are a good programmer but lacking experience in Flash (like me), you keep hitting undocumented brick walls of ignorance and you simply do no development in AS3. If you have AS2 experience but lack formal training in programming, right now what you do is decide that Real Soon Now you need to upgrade to AS3… but you keep programming in AS2.

I would love to be wrong about that, by the way. Is there anybody here who is developing in AS3 and has had some success with it? Sound off, please!

It’s a bit like the move from PHP4 to PHP5. The robust OO model in PHP5 is being largely underutilized, because the programmer base is largely undertrained. The reason so many people say PHP4 is a crappy language is that it allows crappy programmers to successfully write code. I personally take great exception to that notion; I find it bigoted and short-sighted. The very strength of languages like Visual Basic, ActionScript and PHP is that they draw in non-programmers and let them get right to work. But all three languages have undergone the same metamorphosis from a simple toy with toy limitations to a more complicated and proscriptive language in order to enable more disciplined programmers to get more traction.

The definition of “script” has become quite fluid over the past decade. There used to be a clear distinction between interpreted and compiled languages, but with languages like Python being compilable and C++.NET letting you walk the function stack, it’s all pretty hazy any more. Having said all that, the distinction between AS2 and AS3 is pretty meaningless to me. AS2 has much broader community support right now; this will gradually be supplanted by AS3. Mavericks and language purists who don’t mind doing their own research and figuring things out on their own will enjoy jumping right into AS3. Those just looking to get results will want to start with AS2 and then switch to the more powerful (but more byzantine) language becomes extant.

Okay, I really need to stop now. Anyway, I don’t mean to criticize your point; sorry if I come across that way. Thank you for writing an attention-grabbing post. As my good friend Syndrome once put it, “You sly dog! You got me monologuing! I can’t believe it!” :-)

 
Flag Post

The freedom of the language causes programs to collapse under their own weight somewhere between 1,000 and 10,000 lines of code—exactly where is dependent on the expertise (and masochism, heh) of the programmer.

Lol, masochism is the perfect term to describe it. I am still making edits to code that I wrote for a game, which, on the main code frame, tops 10,000 lines of code. The only way I can edit it is by using the ‘Find & Replace’ function and looking for specific function definitions, etc. Now, this is not what I’m going to call good practice, because my use of classes in this program is somewhat of an afterthought. (I have 34 classes, mostly extending the MovieClip class, and mostly used when importing from the library).

BUT… to say, as Dazzer does, that AS 2.0 was simply not designed with programmer in mind, betrays a bit of coder ‘elitism’ which I feel is misplaced. AS 2.0 allows the creation of some pretty darn complex, code-based applications. I know for a fact that most Flash animators (whom AS 2 was supposedly designed for?), wouldn’t have a freaking clue how to read the code that I’ve written in AS 2.0 — that’s because, omg, it’s a pretty powerful scripting language.

 
Flag Post

Really, I think the differences between AS2 and AS3 are really being blown out of proportion. I’m currently developing a relatively large base of code that I can reuse and I’m calling it an “engine” using AS3. I’ve been working on it for a couple months and its probably up to about 4000 lines. I have a moderately sized inheritance tree, about 6 or 7 is the longest chain, and while I’m not using interfaces, it’s kind of complex OOP.

Yesterday I wanted to mess around with some particle effect stuff and wrote about 200 lines of proceedural code, the most complex objects I used were movieclips and arrays, and got a nice little thing going within about 2 hours.

My point is that AS3 is good for pretty much all applications, and there isn’t that much setup to do for simple stuff but it has a lot of good support for OOP and more complex things. The real differences between the two come from the virtual machine, which is much faster for AS3. This is the reason I use AS3, because it’s way faster.

And the most difficulty I had from going between AS2 to AS3 was learning to put “package {” at the start of every class file and getting through outdated tutorials that said I had to import a class just to use trace (which is thankfully resolved, trace() is totally global now).

 
Flag Post

Well, so far, Actionscript 2.0 hasn’t been that hard. The class so far has been easy, and the only code that gives me any trouble: things like creating duplicating movie clips (just got the hang of that today) and a few others that I just stumble on occasionally. Now only if my drawing skills weren’t so crappy.

So far, the class has been nice because the teacher has a few ideas that I would never have thought of. The teacher has been giving us code examples that we can leaf through, and I got some extra credit for attempting an Asteroids clone. Luckily most of the functions are well-documented. Flash has been pretty fun so I might try making a few games and see how that goes.

 
Flag Post

I think some people are a little bit confused as to exactly what as2 is.

Here’s an excerpt from the Help files in Flash:

  • START OF QUOTE *

About ActionScript

The object-oriented programming (OOP) features in ActionScript 2.0 are based on the ECMAScript 4 Draft Proposal currently in development by ECMA TC39-TG1 (see www.mozilla.org/js/language/es4/index.html). Because the ECMA-4 proposal is not yet a standard, and because it is still changing, ActionScript 2.0 is loosely based on this specification.

ActionScript 2.0 supports all the standard elements of the ActionScript language; it lets you write scripts that more closely adhere to standards used in other object-oriented languages, such as Java. ActionScript 2.0 should be of interest primarily to intermediate or advanced Flash developers who are building applications that require the implementation of classes and subclasses. ActionScript 2.0 also lets you declare the object type of a variable when you create it (see About assigning data types and strict data typing) and provides significantly improved compiler errors (see Error Messages).

Key facts about ActionScript 2.0 include the following points:

Scripts that use ActionScript 2.0 to define classes or interfaces must be stored as external script files, with a single class defined in each script; that is, classes and interfaces cannot be defined in the Actions panel.

You can import individual class files implicitly (by storing them in a location specified by global or document-specific search paths and then using them in a script) or explicitly (by using the import command); you can import packages (collections of class files in a directory) by using wildcards.

Applications developed with ActionScript 2.0 are supported by Flash Player 6 and later.

  • END OF QUOTE *

So you see, AS2 supports OOP and strong typing. OK, you can still put code on the timeline that is AS2, but to do it properly you have to go OOP.

Calain: AS can feel like a scripting language, IF you are programming on the timeline. Try using classes and you’ll see it’s a bit different. Both Java and Actionscript are compiled in to byte code – Java is a programming language, so why do you say AS2 is not? You don’t see 20,000 line AS2 programs cos there is no need – you don’t need to control the screen updates and stuff like in most other languages – the flash player does a lot for you so you need less code. You are left to concentrate on logic (the rules of the games) and less on logistics (every detail of displaying and interfacing with the player).

I work with designers and they have no clue about Actionscripting – so how is AS2 designed for the designer? Not even AS1 was designed with designers in mind! The strength of flash is the ease of which it brings coders and designers together in one workspace. And using “proper” AS2 makes this a lot easier (code in separate .as files).

 
Flag Post

BUT… to say, as Dazzer does, that AS 2.0 was simply not designed with programmer in mind, betrays a bit of coder ‘elitism’ which I feel is misplaced. AS 2.0 allows the creation of some pretty darn complex, code-based applications.

I know it does. But its still a pain in the **** to do so :)
And I’m trying not to sound Elitist, well, because I am far from elite lol. I started with VB6.0, then next thing was AS2.0. Then I went to AS3.0, and migrated to Java. Not the most common path, I believe.

For me the major benefit of actually moving to AS3.0 was the “advertisement” that AS3.0 is faster. Simple as that. AS2.0 just doesn’t run as fast as AS3.0. So just look at some of the potential games out there that just lags simply because AS2.0 can’t keep up.

Example: StormWinds

Crawls at a steady 25fps, then suddenly for some odd reason the framerate shoots up to 60fps, then crawls again. Doesn’t make for a very pleasant experience when you’re trying to shoot things. (Actually I’m not sure if this is really an AS2 issue, or the GC being cranky… perhaps both)

Granted there are very amazing things that people have done with AS2.0. But this is almost like PS2 and PS3. People are still doing amazing things with PS2, but sooner or later they’re gonna want the power that PS3 gives (even if it takes a bazillion years trying to understand the fricking cell processor). There’s only so much you can push it.