Migrating from AS2 to AS3 - actionscript-3

I would like to know from someone who have already done that, any recommendations and things I have to take a special look, I have seen some articles related to the topic, googled it, etc...
but I would like the advice from stackoverflower x)
I already know object oriented programming in c++, using classes and etc, but I can't quite understand AS3 packages and stuff, but i'm very familiarized with AS2.
Thanks

Drop everything you know, start fresh. AS2 is different than AS3. Don't try to do the AS2 thing with AS3.
Read & Learn the Adobe LiveDocs
Learn how the display list works.
Learn AS3 coding standards, write clean readable code
Learn how to use common actionscript libraries, TweenLite, Gaia framework, RobotLegs, Temple Library, Pure MVC, Away3D, as3corelib etc.
Never ever code inside the Flash IDE actionspanel, there are really nice actionscript editors like FlashDevelop, FDT, FlashBuilder, IntelliJ.

My experience migrating from AS2 to AS3 has been pretty smooth, so smooth that I would never go back and squirm at the thought of maintaining old AS2 code.
Firstly I would get familiar with the display list, here is a good article.
Then I would gain an understanding of the new types in AS3, especially the difference between Number, int and uint as you don't need to lump everything in Number anymore.
Do some reading up on the event system and how you can capture events that have bubbled up from other objects, and how you can use capture and stop them propagating further, and how to avoid unnecessary clicks on nested objects in buttons you create.
Like you say you already know OOP, so I would then suggest limiting timeline code as much as possible, write everything in classes.
XML is handled using e4x which makes xml parsing trivial, you will find this a breeze to work with compared to AS2.
The drawing api is now contained in a graphics library accessible through many display objects.
Get to know a good framework, I highly recommend pure MVC AS3
Finally for animation - there can be only one library - Greensock TweenMax AS3 of course ; )
EDIT :
I have looked around for some resources that I think will be of interest to you, I based these choices on my experiences and what I believe are key areas of research:
Presentation on AS3 by Grant Skinner - Excellent overview that you can refer to time and time again.
Getting Started with ActionScript 3.0 - Comprehensive approach to using AS3 with Flash CS3.
Senoculars tips of the day - because you already code in AS2 you should understand a lot of these tips and how they differ in AS3.

Related

Scala libraries for a GUI with vector graphics

If I wanted to create a "good old" desktop GUI program with some basic selectable vector graphics (arrows, colored boxes, text) to show mostly text and some diagrams (no need for 3D or particles, etc.) that then can be edited by the user, which Scala library would I use, and why? I'd want to build a tool for something similar to drawing diagrams.
Mostly I don't want to use things like D3.js or other web SVG stuff because it is painfully slow and can't show the amounts of content I want it to. But if there are exceptional advantages by using, say, Scala.js, for this purpose, it could be still of interest if there are no better means.
Alternatively, someone can point me to where this had been discussed? Did not find anything on Google or here.
Scala-Swing is a wrapper for Java Swing which is quite nice. As you may know, below Swing lies Java2D, so you will most likely want to look for Java2D based libraries. There aren't that many for Scala that I'm aware of, but more for Java (which you can easily use).
JFreeChart and scala-chart - more for charting
JGraph
JUNG
Processing might have some libraries for your use case
JHotDraw - not sure it's still maintained
NetBeans - not sure it's still maintained
Prefuse
And of course, if it's simple enough, there is nothing wrong with using Java2D directly.

What's the proper way to program in AS3?

I've read a lot of books and watched videos on AS3 and they all teach very interesting techniques that I can harness and use. However, I'm in slight confusion because I've seen different techniques that contradict each other from different sources. For example, I've seen some developers write all their code within the timeline and handle it that way. Other times, I've seen developers handle their code in an .as file in Flex/Flash Builder/FlashDevelop. I know that there is no "right or wrong" way to do it, but what is the more preferred way by professionals?
As of now, I just use my .FLA to hold my assets and I write all my code in .AS.
Major projects shoulds strive to avoid timeline code at all times, since it will quickly become very hard to maintain, understand and version control. In these projects FLA's are mostly used to hold library assets, which are then linked into the project via swc-files.
It's fine to use FLA timeline code for small stuff like banners though.
Absolutely try to avoid timeline code if you can. It can really become a nightmare to read or expand. Using classes is a great way to start branching out of flash as well. As you get comfortable with referencing external files it is important to start using design patterns such as MVC (Model View Controller. It makes maintenance, debugging, expansion and handing off projects easier.
Proper way is to use Object oriented programming (OOP) with design patterns (DP).
EDIT:
From Wikipedia:
Design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
In my opinion design patterns are integral part of OOP (without DP you loose most of the advantages of Object oriented language).
You can learn design patterns for AS3 from this great book: ActionScript 3.0 Design Patterns: Object Oriented Programming Techniques. This book has an active blog with lots of interesting articles.

as3: meaningful object identification while debugging

I wanted to ask if there is a possibility to identify objects in more meaningful way during the debug. e.g. now in flex builder debug panel I see for example:
Object(#12131241241)
And ideally I wanted to have Object(#"field1:field2")... is there a way to do it. I believe in java it can be achieved by overriding toString method of the given class.... Tried same in as3 but it did not work
Not answering your question directly here but there are many community debuggers around that give you more meaningful data. The IDE's Intellij Idea or Flash Develop and there are a few other projects such as http://demonsterdebugger.com/ or http://code.google.com/p/flash-console/ which give you an insane toolset for debugging.

What are the pro and cons of using Haxe over Actionscript-3?

I'm thinking about using Haxe in place of AS3.
What are the disadventages of that? I can think about:
Difficulties with using native AS3 libraries.
Difficulity of debugging after language translation.
Haxe is quite young, it may have some rough edges. Does it?
Does any one of you have expirience with Haxe dark sides?
What are the adventages? I've heard:
Performance.
Multiple targets (But I don't see how that is useful)
Better typing that AS3
Maybe better syntax.
Haxe is big enough that there should be more. What are the pros of Haxe?
Edit:
If there are no real disadvantages then why Haxe is not replacing AS3?
Your first point is surely true. Some "native" libraries (such as Flex) may require a little of gym to be included in your project. In the vast majority of cases it is a quite smooth process. Haxe supports multiple -swf-lib which permit to have the code of the imported assets immediately available in your application. Note that the imported libs are not just embedded but are recognized as code asset, so if your IDE is integrated with Haxe you will have type completion for that too.
About the debugging there are no issues at all for the translation, that because the language is not translated to AS3 but directly compiled to AVM2 bytecode. When the -debug switch is on, the full stack trace with source code references (filename, line and position) is fully preserved. An uncaught exception will point you exactly at the line of code that generated it.
Haxe is not really that young and for sure the AVM2 output is the one with the best support of all. There are no rough edges in my opinion.
Of the pros you have outlined I want to underline that multiple targets can be huge. Of course to take really advantage of it you can't really rely on external libs specific for AS3. Even so there are always big chunks of code that you want/can reuse across projects.
To mention a few other advantages:
macros are a recent addition which add a huge pool of possibilities.
Molehill API is already available for Haxe (SVN version) and Nicolas is working on a Shader system that makes it even bigger.
Haxe is evolving constantly bringing new (important) features at each release.

Why doesn't ActionScript have "generics"?

Can anyone tell me why ActionScript 3, a statically typed language, doesn't have generics? Is it too much work? A historical thing? Is there some way to "fake" it that I haven't picked up yet?
Edit: thanks a lot for the answers! The Vector class is basically what I was looking for, and the other information was helpful too.
The new Vector class is a form of generics that Actionscript 3 now supports when compiled for Flash Player 10. They don't support the specification of your own generic classes, yet.
I think Adobe will implement the ES4 standard eventually. It would be nice if they had a competitor who could push them quicker in the right direction. I was expecting a little more from the updates to AS3 when they moved to CS4, but I suppose the revolutionary Vector class will have to suffice.
It looks like they spent a lot of time beefing up the libraries for Flex and AIR, so maybe they'll go back to improving the language support later, but it probably isn't a real priority. Remember, Adobe is in it for the money, not for the feel good of making the sweetest possible language.
I believe it's a historical thing. ActionScript is based on ECMAScript (JavaScript is also based on ECMAScript). ECMAScript is a dynamically typed language, meaning that variables don't have their type declared. Generics are more useful in statically typed languages, wherein the type of variable is declared upfront. In a statically typed language, without generics you're stuck casting all the time from the root object (for example, Object in Java). This is not a problem in ECMAScript, because you can put anything you want into any data structure.
So why didn't ActionScript add generics when they added static typing to ECMAScript? I can't be sure of that, but I think the premise of your question is a bit off - there are generic-esque containers, such as Vector. I might think they'd keep the dynamically-typed containers of ECMAScript (objects and arrays) for backwards-compatibility, but they already broke that between AS2 and AS3, so I'm not sure.
Parameteric types ( the word 'generics' is usually used in ECMAScript for generic methods, rather than the combination of parametric types and runtime polymorphism used in Java ) were proposed as part of ES4, but ES4 fractured and much of the type system proposed for ES ( including the parts implemented in ActionScript ) are not going into the next version. I can't say whether or not Adobe would want to go that way by themselves.
Let's first get proper containers and algorithms in actionscript and then worry about generics...
as3 is not very different from javascript, btw, so your question would kind of apply to JS as well.