AS3/AIR: Managing Run-Time Image Data - actionscript-3

I'm developing a game with AS3 and AIR. I will have a large-ish quantity of images that I need to load for display elements. It would be nice not to embed all of the images that the game needs, thereby avoiding having them all in memory at once. That's okay in smaller projects, but doesn't make sense here.
I'm curious about strategies for loading images during run time. Since all of the files are quite small and local ( in my current project ) loading them on request might be the best solution, but I'd like to hear what ideas people have for managing this.
For bonus points, I'm also curious about solutions for loading images on-demand server-side as well.

a good idea would be, to create external SWFs, that embed images, that are likely to be used together, if that is possible at all ... something like projectiles.swf, obstacles.swf, enemies.swf, misc.swf .... i don't know ... something that makes sense ... maybe divide assets by levels, or something ... take a simple interface, that allows you to extract assets from an swf ... for example, let there always be a class Assets, with a static method getAll, which returns an Object, mapping string identifiers to corresponding classes, so you will get something like:
function onComplete(e:Event) {//this is the handler for the loading operation
var map:Object = (e.target as LoaderInfo).applicationDomain.getDefinition("Assets").getAll();//should return something like {"bullet1":Bullet1,"bullet2":Bullet2,...}
//do whatever you need to do with it
}
advantages:
images get compressed one against another, so overall filesize will be decreased ...
you drastically reduce request count on your server ...
you don't wind up with n-hundred files, following some name/path convention, or even not (also, you need to have a file index somewhere, to know, which files exist and which don't) ...
you can easily reskin your app by loading a different swf, instead of loading n-hundred images seperately ...
the ultimate advantage of this approach is, that you will have classes, that you can simply instantiate, instead of loading images over and over again ... the first operation is synchronous, the latter is not ... if you really need to do that, consider loading the image in binary form into a ByteArray using URLLoader, and then getting it on stage with Loader::loadBytes ...
you may want to generate the swfs on serverside using swfmill, to automate the process ...
greetz
back2dos

for you project
u can make solution using amfphp and mysql blob-storage.
in this link u can take understand how mysql blob-storage.
http://www.anyexample.com/programming/php/php_mysql_example__image_gallery_%28blob_storage%29.xml
and for amfphp please visit
http://www.amfphp.org/
and also please check this AMFPHP Live JPEG Encoder too,
http://www.bytearray.org/?p=90

The solution that I ended up settling on was to create a reusable singleton loading class which manages the loading and storage of data on-demand. It manages "jobs" which can be LOCAL or REMOTE which store references and the loaded data itself which is mapped in the manager class once it has fully loaded.
While I really like back2dos's suggestion, managing the (re-)creation of SWF's everytime an asset changes isn't optimal for my purposes.

Related

Bypass preloader and load meshes from GWT server side

I currently have 6 animated models each between 5Mb and 8Mb each. When using each one individually it can take a little time to download them. I need to load these models up as and when I need them and not in the preloader of libGdx. All 6 models will take a long time to download in the preloader so I'm trying to bypass it.
I've used both GWT and libGdx many times but not together. This project is purely a html one and I'm familiar with classes that need to be serialised so data can be transferred back and forth using GWT's RPC methods.
So far I've come up with 2 ideas of doing this:
Transfer the model data and rebuild the mesh from scratch. This
would take a lot of time and just wouldn't work. Plus it's likely I'll lose such data like animations.
Using LibGdx's
ModelData class which would work perfect, but unfortunately non of
the main class and sub classes are serialised.
The current project has interfaces that bridge the platform specific from the 'core' to the 'html' which can then async the RPC calls. These work with libGdx just great.
Is there a way of skipping the preloader and loading the models on demand when they are needed?
If you need anymore information I'll be glad to add that in.
Take a look at the Dynamic Asset Loading with libGDX and GWT example by MonsterOfCookie: https://github.com/MonsterOfCookie/libGDXGwtHtmlExample
Disadvantage is that you have to compile your own libGDX fork because Monster's PR was not merged. (But for working seriously with libGDX' GWT backend you'll probably need your own fork anyway)

HTML5: accessing large structured local data

Summary:
Are there good HTML5/javascript options for selectively reading chunks of data (let's say to be eventually converted to JSON) from a large local file?
Problem I am trying to solve:
Some existing program locally and outputs a ton of data. I want to provide a browser-based interactive viewer that will allow folks to browse through these results. I have control over how the data is written out. I can write it all out in one big file, but since it's quite large, I can't just read the whole thing in memory. Hence, I am looking for some kind of indexed or db-like access to this from my webapp.
Thoughts on solutions:
1. Brute-force: HTML5 FileReader API has a nice slice() method for random access. So I could write out some kind of an index in the beginning of the file, use it to look up positions of other stored objects, and read them whenever they're needed. I figured I'd ask if there are already javascript libraries that do something like this (or better) before trying to implement this ugly thing.
2. HTML5 local database. Essentially, I am looking for an analog of HTML5 openDatabase() call that would open (a read-only) connection to a database based on a user-specified local file. From what I understand, there's no way to specify a file with a pre-loaded database. Furthermore, even if there was such a hack, it's not clear whether the local file format would be the same across browsers. I've seen the phonegap solution that populates the browser local database from SQL statements. I can do that too, but the data I am talking about is quite large (5-10GB): it will take a while to load, and such duplication seems rather pointless.
HTML5 does not sound like the appropriate answer for your needs. HTML5's focus is on the client side, and based on your description you're asking a lot out of the browsers, most likely more than they can handle.
I would instead recommend you look at a server-based solution to deliver the desired goal/results to the client view, something like Splunk would be a good product to consider.

AS3 - Load only certain items/objects from external SWF

Is there any way possible to say, have A.swf use only certain items from B.swf, without having to load the entire swf as a child first? What i'm trying to do is have A as lite as possible and pull some items from time to time from B without having to cache the entire file in flash memory somehow. I've looked at other similar questions but none seem to really answer or fit this exact problem.
Before anyone asks, yes I do know how to use loader, loadercontext, and create instances of classes from the library. This is more of a methodology question rather than a "how to" question.
Only idea I can come up with, is to export all of the children as individual swf objects and then have A request B to compose itself of the seperated items that get requested by A. Would this be efficient?
I don't think you can do what you want to do, however since the assets are strictly graphical in nature, it doesn't seem inefficient to just export them as individual assets and load them when you need them. ( In fact it seems very efficient to me... )
I haven't tried it, but to save time you could probably automate the export process with jsfl. ( Jsfl lets you script the Flash IDE itself, to automate tasks that you would otherwise have to do manually. ) Take a look at this Stack Overflow answer here:
Generating individual SWF's with classes from a fla with a large library
That example shows how to batch export swfs out of the library.
Note than in Flash CS6 you can export a MovieClip from the library by right clicking and selecting export, but unfortunately it doesn't let you export a group all at once.
A swf is a compiled package, and is not meant to be split into parts. One solution would be to pull all of the common elements out of A and B into a swc (a compiled Flash library, not meant to be run). You can then include the swc in the compilation of A and B.
Unless you will be creating lots of files with only a few common elements, I don't see why you would need to export each of the children as individual swf files.

AS3: How to save every object on stage

I'm trying to make something similar to this:
http://www.personalwine.com/catalog/label_designer_app.php?templateId=5046&action=4C92&userId=0
in Flash IDE with AS3.
My problem is how to save all objects on a stage, save it as a "template" and reuse it again - not as images, but as objects that can be editable again.
Could anyone point me to the right direction on how to solve this problem.
Thanks in advance!
Maybe a xml save/load function could help. Once one created something on save, all attributes of each object are written to a xml file. If you want to recreate, then you parse the info and build the screen.
Where?
You have two choices for saving data, you can either save it on the user's computer (client-side) or on your own server (server-side).
On the server
If you're going to use anything that is server-side related well, obviously you're going to need a server (and a database). Using php with mysql is both free and very fast for this sort of usage (small). You might also want to look into node.js since it will probably come very intuitively to an actionscript user since node is javascript and the syntax and structure of node.js files and actionscript files are very similar.
On the user's pc
If you just want to store the data on the user's computer, you can use a SharedObject, it will save all the data you need (variables and such) on the user's computer.
Here is a short nice tutorial on how to do so:
http://kirill-poletaev.blogspot.com/2010/07/how-to-save-local-data-with.html
Here is a much bigger and more detailed tutorial:
http://active.tutsplus.com/tutorials/actionscript/movieclip-reconstruction-with-the-sharedobject-class/
Basically you can do this for all the variables you want to save (movieclip locations, etc) and then load them. It is very straightforward, you can even store a whole movieclip object.

Testing and mocking with Flex

I am developing a "dumb" front-end, it's an AIR application that interacts with a "smart" LiveCycle server. There are currently about 20 request & response pairs for the application. For many reasons (testing, developing outside the corporate network, etc), we have several XML files of fake data, and if a certain configuration flag is set, the files are loaded, a specific file is parsed and used to create a mock response. Each XML file is a set of responses for different situation, all internally consistent. We currently have about 10 XML files, each corresponding to different situation we can run into. This is probably going to grow to 30-50 XML files.
The current system was developed by me during one of those 90-hour-week release cycles, when we were under duress because LiveCycle was down again and we had a deadline to meet. Most of the minor crap has been cleaned up.
The fake data is in an object called FakeData, with properties like customerType1:XML, customerType2:XML, overdueCustomer1:XML, etc. Then in the FakeData constructor, all of the properties are set like this:
customerType1:XML = FileUtil.loadXML(File.applicationDirectory.resolvePath("fakeData/customerType1.xml");
And whenever you need some fake data (this happens in special FakeDelegates that extend the real LiveCycle Delegates), you get it from an instance of FakeData.
This is awful, for many reasons, but it works. One embarrassing part is that every time you create an instance of FakeData, it reloads all the XML files.
I'm trying to figure out if there's a design pattern that is not Singleton that can handle this more elegantly. The constraints are:
No global instances can be required (currently, all the code dealing with the fake data, including the fake delegates, is pulled out of production builds without any side-effects, and it needs to stay that way). This puts the Factory pattern out of the running.
It can handle multiple objects using the XML data without performance issues.
The XML files are read centrally so that the other code doesn't have to know where the XML files are, and so some preprocessing can be done (like creating a map of certain tag values and the associated XML file).
Design patterns, or other architecture suggestions, would be greatly appreciated.
Take a look at ASMock which was developed by a good friend of mine (and a member here Richard Szalay) and is based on .nets Rhino mocks. We've used it in several production environments now so i can vouch for it's stability.
should be able to get rid of any fake tests (more like integration tests) by using the mock object instead.
Wouldn't it make more sense to do traditional mocking with a mocking framework? Depending on your implementation, it might be possible to set up the Expects by reading the fake-data XML files.
Here is a Google Code project that offers mocking for ActionScript.