Is there any ActionScript 3 to JavaScript (and vice versa) migration guide? - javascript

as a skilled AS3 developer I wonder if there is something like AS3 to JS migration guide. After all both languages have a lot in common.
I have in mind something like the old AS2 to AS3 migration guide - a list where I could simply look up the AS3 functionality and the JS counterpart, or vice versa.
I am not saying you can easily convert all your code like that but it would tell me where to start.
PS: I think it is a great idea and if such guide doesn't exist someone should write one :).

I've read that with Haxe you can compile somewhat transparently to JS code. This requires Haxe code, I think, which is not ActionScript 3.0 but is close and should be easy to pick up if you're already comfortable with AS.
I haven't tried this myself but it's probably worth to check out. Here's a blog post that might give you some ideas: http://gamehaxe.com/2010/05/25/javascript-ready-or-not/

You're going to have a difficult time of this considering a lot of the flash.* packages don't have any native JavaScript counterparts. Maybe a robust JavaScript library can ease the transition, but there will be a lot not migrate-able.
However, many of the Top-level datatypes do have a JavaScript counterpart (i.e; Date, Array, String, Object, null, Number/Integer)

Related

Coffeescript tutorials that don't assume Javascript knowledge

I know I'm coming at this the wrong way. You're supposed to learn Javascript first, then start looking at Coffeescript when you get tired of braces and variable declarations. Me however, I'm a somewhat experienced Ruby and Python programmer but with zero Javascript fluency who looks to get into web scripting (mainly through Rails).
I'm convinced that Coffeescript is the way to go for me, but I'm hard pressed to find a tutorial that does not assume significant Javascript familiarity. Most of the tutorials I have seen explain Coffeescript's peculiarities in detail only to gloss over such minor topics as how to actually write web applications.
So, do you know of any Coffeescript tutorials for people who don't know JS to begin with?
You probably don't want to hear this, but I'm going to say it anyway: you should still learn JavaScript first.
JavaScript is a little unique from other languages, in that it has a monopoly over browser scripting. There is currently no other language that can be used in a browser (unless it uses a plugin, or the interpreter is in JavaScript!). As such, for any project that needs to do any amount of client-side scripting, JavaScript knowledge is a must.
You're probably thinking "Hey, I know Python and Ruby, and I never had to learn C or assembly!", which is of course true. But, those language never had a monopoly over their domain. Python can be used for the same things as C, in many cases. The platform doesn't care what language you use, as long as it supports it.
And the browser platform only support JavaScript.
CoffeScript is an abstraction of JavaScript. Although CoffeeScript is compiled into JavaScript, when you're trying to figure out that obscure JavaScript error, or debug a generated function, or are wondering why there are two levels of unnamed function nesting, you're going to want to know what's really going on.
Now, I'm not saying that you have to become a JavaScript Ninja (although I'd recommend it), but what I am saying is that you should come to grips with the actual web language first.
Learn JavaScript, learn its concepts (it's a very fascinating language, in my opinion, once you get past some of the deficiencies), and then use CoffeeScript to abstract away the technicalities.
Since you did ask for a tutorial, though, here's some: First, the Mozilla guide to JavaScript is quite nice. If you want some more advanced topics, there's also an interactive tutorial made by John Resig. And finally, here's a bunch of CoffeeScript tutorials that you probably already know about.
I suggest the free online Smooth Coffeescript book (based on Eloquent Javascript).
No previous programming knowledge is required. CoffeeScript lets you
write web oriented applications simply and elegantly. It is closely
related to JavaScript but without its quirky corners.
Smooth CoffeeScript is a book about CoffeeScript and programming.
Start with programming fundamentals, learn about functional
programming with Underscore and problem solving, study object
orientation and modularity. It covers client/server web apps with
Canvas and WebSockets.
I had a background in Python, ActionScript and Java. I started directly learning CoffeeScript with no intention of learning JavaScript. I learned a bunch of JavaScript along the way but I think it's perfectly OK to set out to learn CoffeeScript directly.
I was first attracted to Smooth CoffeeScript because it claimed to be targeted at folks trying to learn CoffeeScript directly. However, the style of writing was not to my liking. YMMV.
Besides, with my Python background, I found that I didn't need much help with the syntax. I got all of the syntax help I needed directly from he CoffeeScript web page. I mostly needed help with the platform (cake, development environments, testing, etc.) which is covered quite well on the CoffeeScript web page, and what else I needed I got from a couple of other books. My favorite teaching book is The Little Book on CoffeeScript (read in an hour) and my favorite reference is Trevor Burnham's Pragmatic Bookshelf book on CoffeeScript which taught me jQuery from the CoffeeScript perspective.
Another thing that helped me ramp up quickly was to fork/upgrade a few of my own tools in CoffeeScript. I forked the CoffeeDoc repository on github to create my own version and I eventually re-wrote it to create CoffeeDocTest which is like Python's DocTest except for CoffeeScript. My upgrades to the Coda syntax mode for CoffeeScript were accepted back into the master branch via github's pull-request mechanism... after a code review and some cleanup. Looking at someone else's code really helps you learn the idioms. Getting a code review from someone in the know helps even more.
Your question doesn't make a lot of sense to me because CoffeeScript is JavaScript. To know one is to know the other. It may sound counter-intuitive for me to suggest that the best way to learn CoffeeScript is by cracking open a JavaScript book but the languages are one and the same.
I know they look different, but the differences end at the syntactical layer[1]. Add some semicolons, curly braces and parens to CoffeeScript and you're more or less there. So go and learn JavaScript, and you'll find you're learning CoffeeScript too.
You could also learn CoffeeScript and incidentally pick up JavaScript. This may be a little bit more difficult though, since until source mapping is implemented, debugging can only be done in JavaScript (and you'll be debugging a lot, I assure you ;-)).
[1]: Apart from maybe class definitions which are slightly more complicated.

Javascript to actionscript

I am trying to convert some pre-existing html/JavaScript files to Flex. I tried making some research to see if there was any compiler that compiles code from javascript to actionscript. As far as I can see, there are many ways to transform actionscript to javascript, but I couldn't find any for the other way around. Does anyone know if there is a way to do that, or should I just write my own tool?
I think you will find this will not work well, as AS3 is a strict-typed language, and Javascript is not. Even if such a compiler exists, your ActionScript will likely have problems from the fact that it would create a bunch of generic object.
In short: ActionScript to Javascript works, because Javascript is more permissive, but a lot of structure is lost. Inheritance, Type, etc.
But to go the other way, there is no way to add back in the structure required by ActionScript.
As one of the commenters mentioned, you may need to do this conversion by hand.
One other idea: the Flash player can talk to Javascript. There may be no need to convert the Javascript to ActionScript, instead just create a few functions to talk to the Flash SWF file through its ExternalInterface class. Just keep the Javascript in Javascript.
I highly suggest a complete rewrite, it won't take much time since both of them (JS & AS) are ECMA standard languages (correct me if I'm wrong)
But if you really need an automated way, Try:
Converting your JS to haxe
Compiling output Haxe to AS
It's the easiest solution on top of my mind.
You're better off writing your own tool. There are so many different ways to write javascript, and including the fact that it's untyped, it would be difficult to write a be-all end-all solution that converts everything. If it's a library, it might make more sense to convert opcodes rather than code-to-code, but so much of it depends on how the javascript was written.
It's going to be a pain, that's for sure.
js is untyped, actionscript is "typed". I guess everything could be an object and it would work well
js function scoping is handled differently.
anonymous function calling in actionscript is generally frowned upon, and is a detriment to performance
stuff like setTimeOut in actionscript is also frowned upon, enter_frame and timer are probably more useful
garbage collection in actionscript is handled a bit differently -- as is event dispatching

the right time to use coffeescript

So basically I have a number of concerns holding me back from coffeescript:
I'm not really an expert in js yet, even though I'm using it for around 3 years now I still feel like I'm missing something important about it. Since it's mostly a supportive technology for me I never find time to go in depths of js ( which, I admit, might be a wrong attitude ).
My js knowledge will get even worse if I'll start Using coffeescript
I'm not sure if I can actually trust coffescript, meaning the js code it compiles to
At times I don't understand the js code coffeescript compiles to and even worse - why it compiles like that.
I'd like to know your thoughts on the above points. The crucial one is:
How using coffeescript affected your knowledge of js? And how important you think it is to fully understand js before switching to coffeescript?
You should understand what problems Coffeescript is supposed to solve.
And for that, you should have a basic knowledge of javascripts' "bad parts".
I suggest reading Douglas Crawford about that (there's a book, but also a lot of resorces on internet. Just google "javascript bad parts").
Basically, the idea is that "Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way." (taken from coffeescript's site).
There's a tool to assist programmers to avoid javascript pitfalls called jslint.
This tool analizes your code and gives warnings about common mistakes, such as global variables, semicolon insertions, namespace pollution, etc...
Coffeescript translates to javascript. But the javascript it generates is a cannocical subset, highly compliant with jslint.
What's more, it generates javascript code valid on all browsers.
So it is not just a nice syntactic sugar layer, it really helps generate solid code.
I'd like to address your concerns.
1) If you've been using JS for three years, you probably have a pretty solid understanding of JS. If you haven't gained a solid understanding yet, it may be time to supplement your knowledge with one of the good JS books.
2) Coffee-script probably wont make your knowledge of JS worse. The way you design Coffee-script applications is the same way that you would design a JS application (for the most part), so the design skills you gain will transfer over. Program design, in my opinion, is the most important aspect of programming.
3) Why don't you trust the JS? Why do you trust any of the other compilers/interpreters/other tools you use? I doubt Coffee-script is bug free, but many people use it for many purposes. This means that a large set of behavior has been tested, often in production, so your use case has probably already been tried and tested.
4) Of course the JS generated by Coffee-script will look foreign to you, since the rules for generating it don't have human readability as a priority. Reading it, however, will increase your knowledge of JS as you see how peculiarly written programs run. This brings us back to point 1.
I think that the crucial thing to remember here is that Coffeescript IS javascript. Every Coffeescript statement or magic operator has a distinct concrete representation in Javascript. For instance (x) -> x * x in Coffeescript will translate directly to function (x) { return x * x; }.
You can't really write Coffeescript without being aware of the Javascript it will generate. For one thing, the generated Javascript is what you will have to debug. If anything, I believe that writing Coffeescript could possibly improve your understanding of Javascript, because it forces you to make decisions that are unique to Javascript. For instance, when in Coffeescript, you decide to use => instead of -> in reality you are making a decision about whether or not you want to bind this - a very real Javascript problem.
When (or if) to start using Coffeescript? I think the answer to this is more or less up to you. Try it out, and if you feel that it is easier to get your tasks done using Coffeescript, then stick to it. If you find it difficult to write the code in a different language from the one that runs (and thus the one you have to debug), then go back to Javascript.
So here's what I think about the topic:
JS is not a supportive technology (support for what?). It is a language mostly used on front-end and there is a new trend of using it on back-end. Since browser do not support CoffeeScript natively than unless you use it as a back-end then I don't think there is a point in using CoffeeScript. Although learning new language is always a good idea.
Not at all. Actually using CoffeeScript is like using different language. Learning one cannot make you dumber in the other. Unless you stop learning the other one.
There is no evidence that CoffeeScript compiles to buggy or slow code. Actually I am using CoffeeScript for some time and I didn't observe any performance hit.
Actually you don't need to understand why it compiles like this. If you are using CoffeeScript on back-end then you don't even have to look at the code it compiles into (you only need the source code). As for using it to make browser scripts then yes - it may be a bit difficult to work with it (debug). That's why I always advice to write normal JavaScript for browsers and use CoffeeScript on back-end.
Now as for the last question: I don't think that CoffeeScript affected my JS knowledge at all. I treat them as separate languages. Also you don't need to know JS in order to switch to CoffeeScript (although you should) unless you want to use CoffeeScript on front-end.
Also mastering JavaScript is always a good idea, no matter what. :)

Does it make sense for software developer to use jQuery when learning Javascript?

It's often claimed that learning a lower-level language is a good foundation for any new developer. What about an experienced developer (say a C++ or Java guy) learning Javascript? in the same way should he learn using the raw language so he understands what's going on, and learn JQuery later, or use JQuery from the start as 'part of' Javascript?
I think it's worth spending a bit of time working on JavaScript without jQuery so you can appreciate just what jQuery brings you. But most of what you'll be learning in JavaScript (getElementById etc.) will be replaced by better jQuery functions, so don't spend too long in pure JavaScript.
I guess the important thing to realise is that a lot of what you do in JavaScript is actually just working with the DOM API. The JavaScript language is great, but the DOM API is RUBBISH. jQuery doesn't really abstract the language, just the API. So the distinction isn't between using JavaScript or using jQuery, it's more about using the DOM API vs using jQuery.
It's always good to understand the basics of 'raw' JavaScript. I would recommend learning basic JacvaScript first, then jQuery. It'll make jQuery easier once you know the basics of the language, and there are still quite a few scenarios where it's preferable to do parts of a code in regular JavaScript than the jQuery way.
You could still try to learn about both in parallel, but either way it is still important to understand JavaScript to really understand appreciate jQuery.
I am pretty new to JavaScript myself, and I had a few months to learn raw JavaScript before finding out about jQuery. I agree with GSto that learning raw is good, but don't spend to much time in it before looking at a framework.
Apart from that, I strongly recommend anyone building in Javascript to pick up a copy of Douglas Crockford's JavaScript: The Good Parts. Read it back to back and then keep it close to your computer!
JavaScript differs from C-like languages quite dramatically at some points...
EDIT: Crockford held a great talk at Øredev 2009. They have the whole talk in video on their site.
Learn Javascript first and about DOM, object literals, closures and currying. When you master these things you are ready to use a library.
If you want to be a good web-developer who knows javascript, then do not touch jquery for at least year. It will corrupt you. Seriously, I've seen too many people who claim that they know javascript but are unable to iterate through an array without using jquery.
I think you should learn raw language before jquery or another framework. If you do, cou can learn jQuery basis wery quickly.
I learned JavaScript before I did anything with jQuery and I would recommend the same to any one thinking to learn JavaScript, as this would allow you to move to another library or use raw JavaScript if you found that jQuery wasn't really suited to what you need or if you simply didn't like jQuery.
There may be some cases in which using raw JavaScript is better suited to what you want to do.
It's very important to learn the language itself, and somewhat important to become familiar with the issues faced by things like jQuery in making the programming environment more uniform across different browsers. However, except as exercises for people who have the time, attempting to re-implement the facilities that modern frameworks provide is a pretty bad idea.
A benefit of learning a modern framework is that they generally encourage the exploitation of the native power of Javascript, and avoid trying to make the language look and act like something it isn't. You have to develop a good feeling for what anonymous functions are and how they work, for example, in order to really use Prototype or jQuery or just about any other framework effectively.
Finally, reading the source code of a good modern framework is wonderfully enlightening.
Think of JQuery as being an abstraction that just happens to be built using Javascript.
Most things that you need to do can be done elegantly with JQuery.
To use JQuery effectively it is more important to understand the DOM, Events and CSS.
It helps me to think of JQuery and Javascript as being different paradigms even though we all know that JQuery is written in JS.
I came to Javascript from a C/C++ background and it took me a while to really get to grips with the object model first-class functions, inner functions and closures and prototypes.
JQuery is much clearer, easier to follow, and more powerful once you understand what it is that you are manipulation (i.e. DOM, Events, CSS).
So I'd learn JQuery first and fill in the Javascript gaps as they appear.
Don't forget that document.getElementById is still the fastest way of getting elements. So if you do simple stuff and that's sufficient so why use a library?
Read what Joel Spolsky says about abstractions. What happens when your abstraction layer leaks? Do you know why the problem happened, or what you can do to fix it?
I would start learning the javascript syntax and usage first, but don't focus too much on the different functions, as a lot of them will have better jQuery alternatives.
The answer - both.
If you are working on something professionally and have a deadline... JQuery. Then go home and learn the internals. JQuery is very powerful and there is no need to reinvent the wheel. Sometimes the best code you write... is no code at all.
Now that being said, its always a good idea to understand your code and the "black majic" that happens under the hood. This helps to decide which JQuery method or selector to use for the best job... measure the pros vs cons.
You should do both at the same time. Learn javascript loops, types, prototypes and just forget the DOM methods because jQuery is more elegant for that.
You should learn basic js first, variables, loops, functions, closures, inheritance, and js design patterns. If you're already a programmer, you can skip a lot of stuff. jQuery is not a language. Once you know that, then jquery is a tool, that mostly helps you abstract differences between browsers (and provides another dialect of js). I don't use jquery, I use ext-js (another tool, another dialect), so I would caution strongly against learning jquery as if it were a language.
If you're going to work with the DOM (as admittedly most do, since most Javascript is used for client-side web development), then JQuery will be helpful.
However, don't confuse it with the language Javascript - JQuery is just another library for DOM access, albeit a very ubiquitous and imho great one.
I'd say it's somewhat analogous to asking if it's wrong to use Win32 or some other platform API while learning C++.
jQuery is just one of several libraries out there. What are you going to do if you don't use jQuery or the company you work for doesn't? Using this library does carry some weight, too. Are you going to always use it even if you only needed one minor feature?

Should I learn/become proficient in Javascript?

I am a .NET webdev using ASP.NET, C# etc... I "learned" javascript in college 5+ years ago and can do basic jobs with it. But I wonder if it is useful to become proficient in it.
Why should I learn Javascript?
Is it more advantageous then learning JQuery or a different library?
Yes, definitely learn Javascript before you learn one of the libraries about. It's the whole walk-before-you-can-run thing.
Make sure you add these sites to your bookmarks:
Mozilla's developer site: This contains the reference to the Javascript API in Mozilla. This will help you make sure you're writing code that Firefox understands.
IE's site in Microsoft Developer Network: The same, for IE.
W3's reference of DOM for HTML: In most web applications today, the Javascript code manipulates the DOM, which is an internal keeping track of the objects displayed on screen (but you already knew that, right ?) This is the reference to the DOM API. It is language neutral, which means it does not target Javascript, but these methods exist in Javascript too.
Douglas Crockford' site: Doug Crockford is THE MAN when it comes down to Javascript. The articles in his page are a must read. Because Javascript has closures and first-class functions, he believes it is closer to Lisp and Scheme than to other languages. And he teaches you how to greatly improve your code with these language features.
Yahoo Developer network: You may also want to check this. I'm not a regular visitor to this site, though, so I can't really say much about it.
Yes, absolutely you should learn JavaScript if you are doing web development. I highly recommend JavaScript: The Good Parts, by Doug Crockford. And, JQuery is a great framework to use (this site uses it) -- it kind of depends on what you are trying to do -- YUI and ExtJS are also very nice.
The answer is simple.
Hands down yes. There's a reason that Google have made such a big fuss about the V8 JS engine for Chrome, why Mozilla are working on TraceMonkey for Firefox and why Webkit have been working on Squirrelfish for a while (now Squirrelfish extreme). It's because JS is becoming more popular by the day.
Javascript is one of those languages that spending a few hours learning will probably teach you 99% of what you will ever really use. I would imagine you are at the point in your learning of javascript that you know more than enough now and just learn one or more of the frameworks now.
I would recommend brushing up on your non-frameworked javascript first. Refreshing/learning basic concepts of dom manipulation and what not. Like learning how to build a linked list, stack or queue in C++ before learning how to use the STL (standard template libraries).
In addition to brushing up on straight javascript, it might be good to get into a framework that doesn't abstract and change the way things work so much, for instance Prototype. You code with it very much the same way you code with straight javascript. Read through the Prototype code, learn how to make classes, and do some fancy stuff. From experience, I can say reading through the Prototype.js helped me learn alot.
After messing around a bit, then I'd say go for jQuery. If jQuery didn't, literally, change the way you write code I'd say go for it first, but learning how to build classes and js inheritance and what not can be a very important lesson for someone who wants to become fluent in JS.
Learning javascript is recommended for any web application developer. Why?
You will better understand the possibilities, limitations and dangers related to developing a web application
It is a boost for your career, if you are working on a web application that has a user interface.
However, learning javascript is usually a trade-off between a programming language and another. You should consider whether javascript is relevant for your career or project.
Unless you want to really get into javascript, I think you'd be better off learning enough JS to leverage one of the tried and tested javascript libraries out there.
One thing nice about JavaScript is that it is quite different from mainstream languages such as C#, VB.NET or Java. Learning it, especially if you have occasions to use it, will give you another insight on programming, and that's always good. I think it's worth learning it.
If you are doing web development then at some point you are going to get exposed to Javascript or ECMAScript at some point in your career for any one of a number of reasons. At a minimum you should know enough Javascript to be able to be able to validate user input; however, the web is moving in the direction of using more an more Ajax so you should also know enough Javascript to properly leverage one of the major libraries out there such as jQuery.
As some of the other users have noted, you can learn most of what you need of Javascript on a day to day basis in a single day or a couple of afternoons. If you want to get more advanced with Javascript then you are going to have to invest much more time in learning the language but odds are that unless you seek out this type of work that you are not going to encounter something that a preexisting library doesn't already exist for.
If all you want is to do some simple UI-effects and the like, I suggest you just pick a library and go for it!
Using libraries eliminates all the flawed implementations of JavaScript and provides you with an API which is the same across all browsers. And if you're working together with others it is also a great way of implementing code-standards and best practices.
Learning a second programming language is always good.
By the sound of it, JavaScript is a language that you use, to it will be of practical use too. As a web dev, it has been recommended to me in a review that i learn at least basic JavaScript.
A library such as jQuery is essential for web development thse days, so you could learn that too.
I don't think a lot of deliberate learning makes sense (but of course you need some basic knowledge), but I also think after some years of web development you'll become pretty proficient in the language anyway :)
If you are a webdev then yes, you should be proficient with Javascript. Javascript is a major part of making web apps as interactive as desktop apps.
With that being said, learn to use one of the cross-browser compatible libraries like JQuery, Prototype, etc. We do not need to have any more single browser crud created using Javascript, just because any real man/woman rolls their own.
A few things to learn in Javascript:
1. Basic syntax
2. The various flavours of function declaration.
3. Passing functions around and how to use passed in functions.
I recommend Jeremy Keith's books: DOM Scripting and Bulletproof Ajax. After you become more fluent in JS I would recommend a JS library(I use jQuery, but that is not important).
JS is important to learn. You cannot use a framework without the proper understanding of how it works. That is doing things backwards.
i thing you should have a good knoloedge base of language specification and DOM (Document Object Model). it means,you shoud know how find/create "page object" an edit properties. Also you should have an idea of "object oriented" javascript tecniques, which the starting point of a lot of framework. you don't need learn specific framework if you don't use it. simple keep in mind generic base concept!
I'll go with the opposite answer most are putting out there. Learning javascript as a developer these days is almost pointless. The language is similar enough to java/C# that it's syntax and semantics shouldn't be lost on you.
What you should learn is jQuery.
As you use jQuery you'll pick up the most common things you'll ever need from javascript anyway.
If you're involved with the Web in anyway then the answer is "Yes, always". Maybe an embedded or system's programmer could get by without JavaScript, but not a webdev.
Most of the libraries are designed to alleviate some of the pain of interacting with a multitude of browsers. They will not abstract away core JavaScript functionality.
Yes, you should learn JavaScript. Sooner or later you will need to use it!

Categories

Resources