Skip to main content
August 26, 2010
Answered

Proper AS3 coding

  • August 26, 2010
  • 4 replies
  • 846 views

Hi Folks,


I am looking at a fully functioning application written in AS2. I noticed that there are AS2 codes in the 1st key frame of the 'action' layer and also within

the custome made button symbols in the library. There are also stand alone '.as' files which are called by the codes already in the timeline.  What is the

prefered coding methodology when it comes to AS3? Should all code be placed in seperate '.as' files and the only code if any in the timeline should be to

call/initialize the '.as' files? What about the symbols? Should any AS3 code reside within them, like eventhandlers, or should they too be moved to a

seprate '.as' file I hope someone can advise me.Thanks.

This topic has been closed for replies.
Correct answer Ned Murphy

I don't think things should be considered any differently between AS2 and AS3 as far as the proper place to put code goes.  The nice thing about AS3 is that it forces you to at least place code out in the open on timelines instead of allowing code to be hidden on objects.  Where you place the code is not as important as the code you place, but keeping it where it is easy to find should be a design goal.

Not every design necessitates creating class/as files.  Personally, I don't make a habit of having separate files for code, whereas others feel there is no better way of coding.  So whatever floats your boat is proper enough in that respect.

4 replies

Inspiring
August 26, 2010

I totally agree with dmennenoh. I practically don't use Flash and all my development needs are served by FlashDevelop and Flex SDK.

I wouldn't call it a methodology but rather a completely different approach. In order for one to design application in external packages developer must have a certain set of mind. This includes ability to be an application architect for this approach has no prewritten structure/templates (like timeline with frames or symbols with Flash IDE UI supporting creation and manipulation of them). Granted, one must have a pretty good idea about at least basics of OOP.

In my opinion writing code in external classes is a much more robust approach. I believe, based on my experience as well as on OOP concepts, that coding on timeline is much worse (including product quality) than in external objects. Timeline does not offer enough flexibility and introduces awkwardness and bulkiness. I think that some complex applications even cannot be developed at all using timeline only.

Contrary to common perception, OOP approaches and coding using external classes exclusively is actually much easier once paradigm shift occurs. To me, timeline looks nauseatingly cumbersome and outdated.

There are many more reasons that are not obvious for small shop development why code should be written in external .as files. For instance, it is difficult to establish automated deployment strategies. Also, it is very difficult (if not impossible) to manage team efforts with applications coded on timeline. This is to mentions a few.

And an employability aspect.

More and more companies (even advertising agencies) are looking for Flash developers – not Flash designers. This is for a good reason - Flash development is increasingly integrated into tapestry of industrial strength application development. In the majority of cases such companies / departments are managed by people who are not designers and who have very deep knowledge of computer sciences including programming languages like C, C++, Java. They usually have a very slight idea about Flash / AS though but, rightfully, demand someone being able to talk to them in terms they understand as well as to comprehensively control development aspects including code reviews.

And Flash developers who code in external classes are paid way more than timeline coders or designers.

August 26, 2010

Personally, I prefer to keep all my code external to Flash - unless I'm just doing some testing. You don't need any timeline code to initialize your classes either - that's what the document class is for.

Aside from SVN, keeping your code external allows you to use a different editor than Flash - that's a big bonus IMO. I use FlashDevelop for coding and it's so much better than the editor inside Flash...

Last, but not least, by creating classes for your projects you get code reusability, you get classes/objects where the code is pertinent to what it's doing - ie it's much nicer to have 10 classes with say 200 lines of code in each, than one big mess in the timeline with 2000 lines of code you have to hunt through.

August 26, 2010

Depends on the size of your project. If it's just something small (codewise that is) there's really no need to make an as-file but as soon as you make more complex applications you really want to keep the code separate from the fla-file. It's helpful to manage the files in svn or cvs even if you're the only developer on the project and if you're more than one it's an absolute necessity. In my humble opinion of course.

Ned Murphy
Ned MurphyCorrect answer
Legend
August 26, 2010

I don't think things should be considered any differently between AS2 and AS3 as far as the proper place to put code goes.  The nice thing about AS3 is that it forces you to at least place code out in the open on timelines instead of allowing code to be hidden on objects.  Where you place the code is not as important as the code you place, but keeping it where it is easy to find should be a design goal.

Not every design necessitates creating class/as files.  Personally, I don't make a habit of having separate files for code, whereas others feel there is no better way of coding.  So whatever floats your boat is proper enough in that respect.

August 26, 2010

Noted. Thanks