Switching from ActionScript to JavaScript, tips for writing code?

I am quite comfortable with using actionscript3 and flash. I also have some experience with Java. But recently, I started learning JavaScript and node.js. I ultimately want to make a 3d game in threejs, but for now I simply want to make a chat application.

I want to get into the habit of using JavaScript. Unfortunately, I am finding it very difficult to start using JavaScript. The difficulties I am facing are

  • No suggestions for different methods and properties pop up, like they do in the Eclipse IDE and Flash Builder IDE. Like when you press dot after object, it shows all the methods and properties relating to that object and it becomes really easy to see what the parameters are and needed to be passed and stuff.

  • How to organize code? In ActionScript3, I could simply make different classes in different packages. I could then import and use those classes in one main file. How does it work in JavaScript?

  • Functions. I have seen people use anonymous functions in javascript. But I am compelled to write external functions as I am in the habit of it. What is better in JavaScript workflow? What do you advice?

  • How is code executed within a HTML file? So if I have several <script></script> tags and I declare a variable in one of them, can the tags below it and above it access that variable?

13

Autocompletion

Javascript is a dynamic language and it’s impossible to get anywhere near to what you have in Actionscript or Java. Just accept what your IDE (WebStorm for instance) might suggest for you. This goes for any interpreted language really.

How to organize code?

Have a look at requirejs or node.js’s own module require function.

Anonymous functions.

Yes, get use to them. Javascript is very much function-based so you’d just have to accept that part. Here is a great starting point.

Several tags and I declare a variable in one of them,
can the tags below it and above it access that variable?

Nope, only tags below it. Try this:

<body>
   <script> console.log(x); </script>
   <script> var x = 1; </script>
</body>

Console prints “x is undefined”.

My suggestion is to check out Haxe. You should use the stable version (2.10) for now, as version 3 is only in RC stage and many IDEs and 3rd party libraries do not yet have full support.

Haxe should be fairly familiar to you as an ActionScript developer. The way you would write an application would be to create markup and then query for the nodes you wish to add dynamic behavior to and manipulate them.

As for IDEs, the website contains a comprehensive list. If you’re on windows, then you definitely will want to use FlashDevelop. It has a project template for haxe/js to get you started.

You might also be interested to have a look at NME, an ambitious project now backed by BlackBerry, that lets you use the Flash Player API on about every platform.

I suggest you join the Google Group or the IRC channel if you have any problems. The community is very active and friendly.


I should point out, there’s a whole number of alternatives that you might want to consider (they all have some basic resemblance to AS3):

  • TypeScript
  • Dart
  • CoffeeScript
  • ScriptSharp

Personally, I favor Haxe over all of them, because it is both richer in features and not limited to JavaScript, but your needs may be different.

1

No suggestions for different methods and properties pop up, like they do in the Eclipse IDE and Flash Builder IDE. Like when you press dot after object, it shows all the methods and properties relating to that object and it becomes really easy to see what the parameters are and needed to be passed and stuff.

This isn’t really my cup of tea, but I’m sure there are Eclipse plugins that can do this to some extent for JavaScript. Due to the nature of functions and the object model in JavaScript, it would be much harder to do this for all cases than a language like Java.

How to organize code? In ActionScript3, I could simply make different classes in different packages. I could then import and use those classes in one main file. How does it work in JavaScript?

Check out RequireJS. As far as I know, it’s the most commonly accepted method for formatting JavaScript “modules” (which are a JavaScript idiom).

Functions. I have seen people use anonymous functions in javascript. But I am compelled to write external functions as I am in the habit of it. What is better in JavaScript workflow? What do you advice?

You can write a lot of JavaScript without having to resort to anonymous functions, but anonymous functions make it easier. I think this is something that you can learn in time.

How is code executed within a HTML file? So if I have several tags and I declare a variable in one of them, can the tags below it and above it access that variable?

The tags below it will have access to that variable. Code is executed linearly, and JavaScript’s scoping is simple, limited, and oft criticized (but efficient if you know the caveats).

For IDE:s consider using something that has good autocomplete support like visual studio, aptana or webstorm. These will make your life a lot easier.

For class-like structures consider Module pattern.

http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

Check out Douglas Crockfords book good parts
and maybe check out some book on javascript patterns.

Because there aren’t any classes don’t mean that there aren’t any good
solutions to organising code.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật