what is tool for actionscript development in image processing - actionscript-3

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.

Related

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

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.

Cocos2d-x 2.0 - How do I Take Advantage of Sprite Auto-Batching Work?

I have seen references to a new 'auto batching' feature in Cocos2d-x 3.0, and even saw somewhere that they no longer recommending using SpriteBatchNodes. So how do I batch draw calls without using BatchNodes?
I can't find anything in the documentation but the vaguest references to this feature.
- https://docs.google.com/document/d/17zjC55vbP_PYTftTZEuvqXuMb9PbYNxRFu0EGTULPK8/edit#heading=h.3ssqg87hovgw
I tried simply getting rid of my SpriteBatchNode and creating my Sprites using files but the number of draw calls went up by about 1 per sprite :)
I think I have solved this, and it's pretty simple. I just changed all of my SpriteBatchNodes to Nodes and preloaded my atlases with
SpriteFrameCache* spriteFrameCache = SpriteFrameCache::sharedSpriteFrameCache();
spriteFrameCache->addSpriteFramesWithFile("spritesheets/xxx.plist");
The number of draw calls didn't change compared to what it was with SpriteBatchNode.
This new architecture is way more flexible than SpriteBatchNode. For example, the calls are properly batched if you do
Node -> Node -> Sprite
where you could never do
SpriteBatchNode -> Node -> Sprite
because SpriteBatchNode could have only Sprites as children.

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.

StackOverflow Errors caused by flood fill: How to stop the error?

For my level editor in my game, I have a floodfill function. The map has a size of 3600 tiles (60 by 60), and I get a stack overflow error from my floodfill function (as it calls itself).
If I only floodfill a smaller radius, it works fine. How do I stop the error from occuring?
Alternatively, is there a way to tell the flash runtime to clear the stack as there is no need to return back to the function?
You need to make a flood fill function that doesn't rely on recursion because Flash's stack is quite limited. You can find some non-recursive ways on Wikipedia: http://en.wikipedia.org/wiki/Flood_fill#Alternative_implementations
I'm guessing you might be using a simple recursive implementation of flood-fill; that algorithm can create deep stacks. It's possible you could implement one of the more efficient queue based algorithms and save the stack, however I would suggest using the already built-in flood-fill capabilities of the BitmapData object.
BitmapData is provided by the Flash Player and has a pretty fast and stack friendly flood-fill implementation.
I was playing with flood-fill algorithms a while back and ended up using the built-in APIs mainly because of the speed advantage -- as well it's compiled C code vs ActionScript.
Here are the docs:
flash.display.BitmapData floodFill()

FLVPlayback component memory issues

My website is entirely flash based, it moves around a 3D model which was given to me as chunks of video that I've converted to FLV files. I'm using the FLVPlayback component to control the video inside of my program. While running memory checks using System.totalMemory I've noticed that whenever a video is loaded, it will eat up a chunk of memory and even when I remove all the event listeners from it(they are all weakly referenced), remove the component from its parent, stop the video and null the component instance, it still will not give that memory back.
This has been bothering me since I started working on this project because of the huge amount of video a user can potentially instantiate and load. Currently every video is loaded into a new FLVPlayback instance whenever it is required, but I have read that perhaps the best way to go about this problem is to simply have a global FLVPlayback instance and just reload the new video into the old instance, that way there would only be one FLVPlayback component in the application's memory.
Has anyone else run into this problem as well? Have you found a better solution than using a global instance that you just re-use for every new video?
I've never really liked the components, they're a bit dodgy. This particular problem seems to be common, and the somewhat annoying solution is, as you're suggesting, to only have one FLVPlayback and reuse that.
Here's a blog post about it
You can't help the memory problems much until Flash adds destructors and explicit object deletion, unfortunately. See this thread:
Unloading a ByteArray in Actionscript 3
There's a limit to how much memory Flash applets can use; the GC seems to fire upon reaching that limit. I've seen my memory-easy applets use as much as ~200MB, just because they run for hours on end and the GC doesn't want to kick in.
Oh, and I don't think using a single instance is an elegant solution, either. Currently I just write a dispose() function for my custom classes, waiting for some day when it can be turned into a proper destructor.
From what I gather after a lot of testing is that flash dynamically loads in libraries and components as needed but never garbage collects that data. For instance, if I have a website or an Air app that uses the FLVPlayback component, the actual component and libraries associated with it aren't loaded until a new FLVPlayback() instance is created. It will then load in the library and component into memory but you will never get that space back until the program / website is closed. That specific instance with the video inside of it will get garbage collected and release some memory as long as you remove listeners from it, take it off the stage, and set it to null.
Also, if you are doing individual videos, the VideoPlayer is much lighter weight, and cleans up nicer.
Thanks for the responses, the links to the other blog questions were helpful as well, I had read all of Grant Skinner's info on garbage collection too, but searching through those links and going back and re-reading what he had originally said about GC helped refresh the old noggin. In addition to nulling and re-instantiating that single FLVPlayback component, I also realized that I wasn't correctly unloading and destroying my Loader instances either, so I got them cleaned up and now the program is running much more efficiently. I would say the memory usage has improved by around 90% for the site.
#aib I will admit the single instance solution isn't elegant, but because flash just won't let go of those FLV files, I'm kind of stuck with it.
#grapefrukt I detest the flash components, they typically cause more grief than time saved, however in this case I had a lot of cue points and navigation stuff going on with the video files and the FLVPlayback component was the best solution I found. Of course I'm still fairly new to the ActionScript world so perhaps I over-looked something.
Unfortuantely, thats just the way flash handles it. Not particularly smart, but it works for most people.