What is an 'action' layer in Adobe Gaming SDK context? - actionscript-3

I am using IntelliJ and Adobe Gaming SDK (Adobe Air & AS3) to learn how to write a game. In the tutorial I'm following, the author mentions an 'action layer' in an the main .fla file. This is about mid-way down the page.
I don't have a main .fla file, just .as source files. Is there a place for me to put the kind of code to which the author is referring? Here is a snippet:
stop();
//setting vars to step in for turns and special blocks
var S:String = 'START';
var F:String = 'FINISH';
var U:String = 'UP';
var R:String = 'RIGHT';
var D:String = 'DOWN';
var L:String = 'LEFT';
var startDir:String;//the direction the enemies go when they enter
var finDir:String;//the direction the enemies go when they exit
// ...and more
It appears that as some examples have demonstrated, this is where key mapping/binding would also be added for event handlers, etc.
My question is, since I am not using the Flex SDK, and have a pure ActionScript module, where do I put this type of source?

This is just typically the layer in the IDE that people put the majority of their code in. It's just a way of organizing stuff. There can be specific reasons to put things in different layers for utility purposes but usually this is more of an organizational technique than anything else. In other words I wouldn't worry about replicating that part too much.
So more to the point, there isn't such a thing as an "actions layer" per se, rather, the author of that tutorial is making a new layer to write some code in and he named the layer "actions" which has been a common method.

I don't have a main .fla file, just .as source files.
So does pretty much every development environment (including the Flex SDK) except Adobe Flash/Animate.
If a resource mentions layers, it is employing Adobe Flash/Animate as the tool.
The problem is, it provides much more than just layers: there are drawing tools, a library, etc. That's why I would not recommend following that tutorial. It will continue to mention tools and workflows specific to Adobe Flash/Animate, that will not apply to your tools and there might not be a simple substitute.
You wouldn't want to follow this tutorial anyway as it's full of bad practices.
On the website of the Adobe Gaming SDK it is mentioned that it comes with all kinds of examples and resources. I suggest that you checkout those and try to get started with them. It's very hard to find good quality resources for Actionscript (not saying there are none), which is why it's a good idea to stick with the official resources.
where do I put this type of source?
That depends on what the source is doing. Some of it might go into the constructor of a class, functions might become methods of a class, etc. Object oriented code usually has more structure than the imperative code you see there, which means that there's no 1 to 1 conversion. It takes experience with the language to make a good translation between the two. As you are just starting out, a tutorial based on Adobe Flash/Animate is not the best starting point.

Related

what is tool for actionscript development in image processing

i am building a image processing web application. i am new to Action Script. I am confused whether to use Adobe Flash Professional or Adobe Flash Builder. I have surfed a lot, but unable to conclude anything.
Also please suggest me some good tutorials regarding action script.
It will be very grateful.
You can do pretty much any kind of image manipulation you want to via Flash Builder and the Apache Flex SDK. I do a lot of this type of work. You can manipulate pixels however you want in ActionScript. You can also perform neat tricks for storing the pixel data. For instance, I make videos from sprites and from things people draw on the stage. To conserve space in the final constructed sprites, I am able to do things like this:
var bitmap:Bitmap = loader.content as Bitmap;
var bitmapData:BitmapData = bitmap.bitmapData;
var byteArray:ByteArray = new ByteArray();
byteArray.writeUnsignedInt(bitmapData.width);
bitmapData.copyPixelsToByteArray(bitmapData.rect, byteArray);
byteArray.compress();
BTW, if you want to save these images locally, use a FileStream and the File.applicationStorageDirectory.resolvePath() function.
Then, when you need to get your compressed bytes back into an image, you can do this:
var bytes:ByteArray = bytesFromStoredByteArray;
bytes.uncompress();
var width:int = bytes.readUnsignedInt();
var height:int = ((bytes.length - 4) / 4) / width;
var bitmapData:BitmapData = new BitmapData(width, height, true);
bitmapData.setPixels(bitmapData.rect, bytes);
There are many methods in the API for manipulating pixels. You can pretty much do anything you want to do with Flash Builder and the Apache Flex SDK.
When I first learned, I used the Flex in a Week program that Adobe supports. http://www.adobe.com/devnet/flex/videotraining.html
However, while Flex in a Week will teach you about Flex, I personally don't recommend you use Flex too often. I use Flex in a very limited context and use ActionScript anywhere and everywhere I can. I never used any tutorials to learn ActionScript. Instead, I just looked at the API whenever I needed to know something and since the programming conventions are very similar to Java - which I already knew well - it was fairly easy for me to get up to speed with ActionScript. If you have not worked with an asynchronous language before, however, I would recommend you learn about the event model in ActionScript and know that you must use it. You should never just run a loop and expect your program to produce what you think it should produce. Use Flex for most UI components you want to render and ActionScript for any programming logic you need to implement.
Another bit of trouble to look out for is that often times in AS you can use the event model and still cause your program to crash. So, if you have a large set of images to decompress or manipulate in some way, put in Timers to keep your program from freezing. If I have a lot of work scheduled for my app to do, I will allow relevant part of the program to to run for 20 MS and then time it out for 50 MS. By doing this, the rest of the app stays usable and people's systems don't crash.
Good luck. If you have specific questions about image processing, manipulation or ActionScript, I'm happy to help.

AS3 How can one detect that a display object is subject to a motion tween?

I guess this is a question for real gurus only..
I'm using the Flash Authoringtool to create MovieClips, yet I play them using my own engine (which behaves better for mobile).
Yet, for proper behaviour, given a DisplayObject, I need to know if its parent is tweening it inside the MovieClip it is part of.
I've already come up with Brute-force and non-elegant ways to do that:
In the authoring tool, add a prefix to the name of any movieclip that is subject to tweening. That name prefix can be checked lateron at any moment. Of course, as this prefixing is a manual process, it's easy to forget or mistype one.
In the code, play each sub-movieclip of the main movieclip for all of its frames, and for all of its children, detect if the transformation matrix changes at any of these frames. If so, automatically prefix their names. Although automized, this solution may take up noticable time for larger movieclips.
So what I'm hoping for is that some other way exists like:
if((dpo.parent) as MovieClip) != null)
{
bDpoIsBeingTweened = ((dpo.parent) as MovieClip).someProperty;
}
Looking forward to any elegant solution.
The solution is quite simple: stop using Adobe's tweening library.
Use TweenLite which is hundreds of times faster, easier to code, and has many other benefits. For example being able to use isTweening to determine if some object is being tweened or not.
Here's the documentation.
To include external libraries in the Flash IDE you can do it in 2 ways.
1) Copy the folder of the external library in your project folder (where your .fla file is)
2) Define a folder in "File > Actionscript settings" where you want to put external libraries files in your hard disk.
Then in your code you just need to import those classes with import. For example:
import com.greensock.TweenLite;

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.

Migrating from AS2 to AS3

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.

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.