Showing posts with label as3. Show all posts
Showing posts with label as3. Show all posts

Wednesday, July 20, 2011

Out of Memory Error in Flash Builder 4

Out of memory errors are no fun! Perhaps I can help you fix yours?

Problem: You're developing an AIR application with a significant (150+) number of embedded assets and you're using FB4. Eventually, you'll add the straw that breaks the camel's (compiler's) back and you'll start getting:

An internal error occurred during: "Building workspace". Java heap space

Solution: The issue is with FB4's compiler and the way it handles large numbers of [embed]s... The only way around the OOM error is to off load the assets to run time, rather than compile time.

In my project, I created separate swfs for imgs, snd/music, CSVs and loaded them @ run time which contained static embeds. No more OOM! W00t!

Another good idea, you can also bump up the default memory allocations for FB/Eclipse in general. Here's a description on how to do that.

Lastly, here's a quick and dirty AssetMgr class that will load in a swf and give access to its contents. This will get you started on the aforementioned solution. (Much thanks to Ian's response on Stackoverflow for giving me this suggestion!)



package{

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;


/**
* <p>This Asset Manager class loads a swf and gives access to its embeded class objects.</p>
*
* <p>AUTHOR : Jason Leon</p>
* <p>CREATION DATE : July 21, 2011</p>
*
*/

public class AssetMgr {
private var _appDomains:Array = [];
private static var _instance:AssetMgr;
private var _ready:Boolean = false;
// path to asset lib
private const SWF_PATH:String = "swf/AssetLIB.swf";

public function AssetMgr(){};

/*********************************************************
* retrieve instance
* *****************************/
public static function getInstance():AssetMgr {
return _instance = (_instance ? _instance : new AssetMgr()) as AssetMgr;
}

/*********************************************************
* initialize
* @Desc: must complete before assets are accessed
* *****************************/
public function init () : void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleAssetsLoaded);

var request:URLRequest = new URLRequest(SWF_PATH);
loader.load(request);
}

/*********************************************************
* Handle payload
* @Desc: saves Loader data to _appDomains obj
* *****************************/
private function handleAssetsLoaded (event:Event) : void {
var appDomain:ApplicationDomain = LoaderInfo(event.target).applicationDomain;
_appDomains[SWF_PATH] = appDomain;
_ready = true;
}

/*********************************************************
* Request Assets from saved Loader data
* @Param 1: assetName is the literal name of the asset you want to access
* @Param 2: fileName is the literal name of the loader assets (example: SWF_PATH)
* *****************************/
public function getAsset (assetName:String, fileName:String) : Class {
if (_ready) {
var assetFileAppDomain:ApplicationDomain = ApplicationDomain(_appDomains[fileName]);
var assetClassDefinition:Class = assetFileAppDomain.getDefinition(assetName) as Class;
return assetClassDefinition;
} else {
throw new Error("initialization has not completed");
}
}
}
}


Is this not what you're after? You may also want to look into this thread on adobe's site for your OOM needs... It was not the issue that I ran into but did help narrow it down so I could find my solution.

[NOTE: There is a cap to how many [embed] tags you can include in each swf library you create. I haven't bothered to count to see what the limit is but I've certainly run across it so beware.]

Wednesday, March 30, 2011

Local DB Tutorial (sqlite)

I just followed this tutorial for sqlite and found it useful! Perhaps you will as well?

http://www.adobe.com/devnet/air/flex/quickstart/articles/simple_sql_database.html

Tuesday, January 25, 2011

Sun Flares in AS3

Here's a little AS3 mimic of undulating sun flares using the drawing API. There are two different drawing styles, pointed or curved, which are modified via the ALT view btn. The slider controls the strength of the rays.

Tuesday, January 4, 2011

Chroma Key Experiment



I did this experiment about a year and a half ago. I wanted to see if I could set up a green screen, capture a human walk cycle, and implement it into a flash game.

[be sure to click on the game screen before attempting to move the avatar]

http://www.jasonleon.com/tests/chromakey/

The process I used to extract the background for my walk cycle is called Chroma key compositing. It's the same trick that the local news uses to show the weather (wo)man in front of a weekly forecast.

I made my green screen background with green felt. Just a tip, you'll need a ton of light sources. I had the equivalent of 4 flood lights which wasn't powerful enough to eliminate all of the shadows. Shadow was what caused the distortion that surrounds the edges of my avatar.

All in all, fun project. I never really had time to mess with it further but there are certainly some neat concepts that could come from it.

Wednesday, November 10, 2010

Shattering a bitmap

More work with fractals.



I generate shards of a source image by recursively branching over-top it, after which, I create a mask out of the voided space and then copy the source bitmapData to those voids.

Very convincing effect!

Go here to see the prototype. Click the sprite to see the effect.

You'll need to click on the sprite to shatter it :)

Friday, November 5, 2010

Brownian Tree with AS3

I've been messing around with fractals lately. Here's a fun test I put together:



My inspiration came from here!

Tuesday, November 2, 2010

Particle System



So, I'm working on this game and they were using a super cheesy decal system to depict bullet impacts on NPCs. I came up with this app as a test to see what a pixel blood particle sys could look like:

[Instructions: Produce a projectile by clicking anywhere on the left half of the screen. If the projectile comes in contact with the sprite, a particle emitter will be placed at the point of impact.]

Try It Out Here!

I did a couple more passes of optimization for what went into production but, regardless, I'm still happy with this test. You'll see roughly 150 particles moving about at 50 FPS, not bad.

Saturday, October 30, 2010

Sierpinski Carpet with AS3

After stumbling across this wikipedia article: http://en.wikipedia.org/wiki/Sierpinski_carpet, I thought the world would be a better place if I ported it to AS3.

I'm not sure what you'll use this for but, in case you needed one, here's a Sierpinski Carpet class!

Impress your friends with stylish images such as this!



SWF here:
example

SRC here:

IsSierpinskiCarpetFilled.as

default app file (SierpinskiCarpet.as)

Tuesday, September 21, 2010

Bitwise

I do apologize for the brevity of my blog posts over the last few months... I've been slammed!

This post will be no exception... However, here are two links that, when used together, will make for some interesting reading and experimentation:

http://www.gamedev.net/reference/articles/article1563.asp

http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/

Friday, August 27, 2010

createGradientBox Method

This is neat... he helps us visualize how the parameters of the createGradientBox Method actually affect the outcome:

http://polygeek.com/1676_flex_creategradientbox-explorer

Monday, July 12, 2010

BitmapData Test

I've become interested in bipmapdata so I started a series of tests to see what it was capable of... I though that this test was neat... it demos 300 points randomly bouncing round the screen.

Click anywhere to start them animating and click again to reset:

http://www.jasonleon.com/tests/bitmapTests/randomPixels.swf

Monday, June 28, 2010

Text Layout Format

I just stumbled across this today:

http://labs.adobe.com/technologies/textlayout/

It's a neat addition to the adobe text toolset. You'll have to require the 10 player but in return you get the following:


  • Additional character styles, including leading, ligatures, highlight color, underline, strikethrough, case, digit case, and more.


  •      
  • Additional paragraph styles, including multi-column support with gutter width, last line justification options, margins, indents, paragraph spacing, and container padding values.


  •      
  • Control of additional Asian text attributes, including Tate Chu Yoko, Mojikumi, Kinsoku Shori Type, and Leading model.



  •      
  • You can apply attributes such as 3D Rotation, Color Effects, and Blend Modes to TLF text without placing it in a movie clip symbol.


  •      
  • Text can flow across multiple text containers. These containers are called threaded or linked text containers.


  •      
  • The ability to create right-to-left text for Arabic and Hebrew scripts.


  •      
  • Support for bi-directional text, where right-to-left text can contain elements of left-to-right text. This is important for embedding English words or Arabic numerals within Arabic/Hebrew text, for example.

About Me

I produce and engineer games and applications. | Portfolio | LinkedIn