[Tip] Fix AS3-Flex Error #2032 Stream Error

Recently I encountered an error #2032 within a two year project in Flex, for three days I struggled with it and tried almost everything, this is why I’m posting this here so that it might save someone else time.

This error occurred when I tried to do an HTTPService call to the Back-End and send some really heavy file. The file would require Back-End parsing and when that was over it would return a result. However mid-way the POST call would be interupted and I was presented with a #2032 Stream Error fault.

The solution was both simple and extremely hidden and in my opinion stupid. In the HTTPService I had set the property:

this.requestTimeout = 3800;

However as shown in this post: http://stackoverflow.com/questions/8820715/flex-httpservice-times-out-anyway

This property is NOT taken into consideration by the HTTPService.

It needs:

import flash.net.URLRequestDefaults;
URLRequestDefaults.idleTimeout = 1200000; // or any amount of time in ms

This way we override the default timeout of EVERY call and thus the request no longer fails…

I truly hope this helps someone as the above post helped me.

Flex / Air post apocalyptic battleship game [Post-Grid]

Hello, I have just released a new Flex/Air game on ActiveDen. Check it out!


– It features smart A.I to play against.
– Source files include cross-platform Air application AND Flex Web-application.
– High customization available.
– Based on latest Official Adobe Flex SDK (4.6)

You can find it here: LINK

AS3 send BitmapData to backend efficiently

I was recently asked to send a medium/large file to a backend server running with php. At first I tried sending byteArray but that got messed up from JSON.strigify then I thought to convert the byteArray to base64 format. Although it worked an image of 500×700 occupied ~500kb on the database so it was unacceptable.
The solution was to compess the byteArray and send it, and then decompress it when I received it again. And here is how I did it:

public static function deconstructBitmap(bmp:BitmapData):Object
            // converting the bitmapdata into a byteArray
            var byteArray:ByteArray = bmp.getPixels(bmp.rect);
            // compressing using the default algorithm 'zlib'
            var enc:Base64Encoder = new Base64Encoder();  
            var b64;
            // joining all in one line
            b64 = enc.drain().split("\n").join("");
            // the rectangle is needed for re-contstruction
            return {'bmpData':b64,'rect':bmp.rect};

And now we have a compressed byteArray with our bitmapData the 500×700 bitmap data now occupies ~13kb on the database!

And here is the re-construction of the byteArray into bitmapData ready to be inserted to


or any other component.

public static function constructBitmap(obj:Object):BitmapData
            // to avoid errors
                var dec:Base64Decoder = new Base64Decoder();
                dec.decode(obj.bmpData); // decoding using the same algorithm
                var newByteArr:ByteArray=dec.toByteArray();
                // end of decoding //
                var bitmapData:BitmapData = new BitmapData(obj.rect.width, obj.rect.height);
                bitmapData.setPixels(bitmapData.rect, newByteArr);
                return bitmapData;
                return null;

And thats it, two simple functions to make you and your database happy!


Capitalize first letter of a word JS & AS3 (quick tip)

After 10′ of searching for a fast solution I came up with this, I suspect there is a much cooler way of capitalizing with AS3, but if I can’t find it on 2 pages of search results it pretty much doesn’t exist…
So here we go, this might work only for single words but that was the intention.

function capWord(source) {
var cap = String(source).substr(0,1);
cap = String(cap).toUpperCase()+String(source).slice(1);
trace('A capitalized '+cap); // A capitalized Word
window.console.log('A capitalized '+cap);


Re-arrange objects in a VGroup by Drag&Drop (Flex Spark)

Adding drag and drop support for Group components, as well as swapping of children or reorder.
This might seem like a straightforward issue and an easy solution, but as I found out… only list based views have the ability to re-arrange their children via dragging and droping. But there is one hidden gem, all the Group based components have build-in support for drag and drop operations, and whilst the user cannot enable directly the dropEnabled option (which allows the re-arrange like operation), it is fairly easy to create a custom functionality to imitate it.
Continue reading

TweenMax Bezier example

Hello all,

I haven’t post in a while but I have been quite busy creating some exciting stuff that I will be posting in the coming months.

For starters I thought to post an example of a bezier line as explained in the greensock forums. This is not entirelly my code but rather a re-creation from the .fla

So lets begin:

Here we create the main circle that will tween along the bezier path.

public function createMC()
var circ = new Sprite();
circ = new Sprite();
circ.name = 'mc';
circ.x = -10;
circ.y = 80;

mc = stage.getChildByName('mc');

var button:Sprite = new Sprite();

button.x = 10;
button.y = 10;
button.width = 30;
button.height = 30;



Now we create the lines and the circles between them:
private function createNodes()
var circ = new Sprite();
for(var i=0;i {
circ = new Sprite();
circ.name = 'obj'+i;
circ.x = i*100;
circ.y = 80;

Now that we have created the lines and circles, we create the functions for the drag events:

function dragMe(e:Event){
            var object = e.target;
            stage.addEventListener(MouseEvent.MOUSE_MOVE, update)
        function stopDragMe(e:Event):void{
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, update)
            mc.x = point_mcs[0].x;
            mc.y = point_mcs[0].y;
        function update(e:Event):void{
            mc.x = point_mcs[0].x;
            mc.y = point_mcs[0].y;

At this point we should have circles that are draggable but the path does not update properly. Now we will exactly that:

function createBezierPointsObject(){
            bezierPoints = [];
            xA = []
            yA = []
            var max:int = point_mcs.length;
            for(var i:int = 0; i < max; i++){
                var curPoint = point_mcs[i];
                    bezierPoints[i] = {x:curPoint.x, y:curPoint.y};
//updating the path as we drag the nodes.
        function updatePath(){
            this.graphics.lineStyle(1, 0x0000);
            this.graphics.moveTo(point_mcs[0].x, point_mcs[0].y)
            var bezierObj:Object=BezierPlugin.parseBeziers({"x":xA,"y":yA},true);
            var pointCount:int=0;
                this.graphics.curveTo(bezierObj.x[pointCount][1], bezierObj.y[pointCount][1],bezierObj.x[pointCount][2],bezierObj.y[pointCount][2]);

for(var i:Number = 0; ipoint_mcs[i].mouseChildren = false;
point_mcs[i].addEventListener(MouseEvent.MOUSE_DOWN, dragMe)
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragMe)


Download the project for Flash Builder here:

View Example here:

Convert RBGA to Hex Tool

Hey all, recently I was searching the internets for a tool that successfully converts uint to hex and vice versa but I could not find anything, so I went and created a tool that converts from RGB/HEX/RGBA/UINT to anything even color percentages.

It has the mocking name of RGBaZR (thus making it trendy with the -zr ending…) and it can be found here:


Android Application Instagib

Yesterday I launched my application in the Android Marketplace called Instagib, it is made on Air with Flex and AS3.

Its a utility application which allows users to exchange info through QR code, even links or contact information. What is important is that the QR works with even the default android QR reader so that no one is “forced” to install the application in order to receive data from someone that has it.

It also features a built-in web-browser using the Air StageWebView, a built-in twitter client! which links open in the application browser so that they can be shared via QR.

Make sure to check it out: Instagib App

I’ll be sure to post some parts of the application as it is free and mostly based on open source libraries.

Leave a comment if you want to request some particular part be explained here.


Create Social Sharing Buttons in AS3

Hey all, recently I had to create a series of sharing buttons for a client so I went all over the internets in search for those sharing urls, then I had to fight against the popUp blockers and externalInterface problems, but I managed to pull it off and I present you with some very usefull functions, if one of those urls here changes drop me a line and I’ll try to find a replacement.

So here we go I’ll present the functions and then a single function that manages the display:

        // FACEBOOK
        private function shareFB(e:Event):void
        // TWITTER
        private function shareTwitter(e:Event):void
        // MAIL
        private function shareMail(e:Event):void
            var request:URLRequest = new URLRequest("mailto:"+address+"?subject="+videoInfo.videoTitle+"&body="+"\n\n Video Link: "+videoInfo.videoLink);            
            navigateToURL(request, "_self");
        // TUMBLR
        private function shareTumblr(e:Event):void
            openPage("http://www.tumblr.com/share/link?url=" + escape(videoInfo.videoLink) + "&name=" + escape(videoInfo.videoTitle) + "&description=" + escape(videoInfo.videoArtist),'_popup');
        // STUMBLE UPON
        private function shareSU(e:Event):void
        // GOOGLE +
        private function shareGoogle(e:Event):void
        // LinkedIn
        private function shareLinkedIn(e:Event):void
        // DIGG
        private function shareDigg(e:Event):void
        private function shareBebo(e:Event):void
        private function shareOrkut(e:Event):void
        private function shareReddit(e:Event):void
        // DELICIOUS
        private function shareDelicious(e:Event):void
        // MYSPACE
        private function shareMySpace(e:Event):void

These are most of the social networks that I could think of, but it is almost the same for everything else I suppose.
And the following is the master function that handles the popup. (This is based on a function used by flowplayer and their sharing plugin, but it is generic stuff).

public static function openPage(url:String, linkWindow:String = "_blank", popUpDimensions:Array = null):void {
            if (linkWindow == "_popup" && ExternalInterface.available) {
                var dimensions:Array = [800,600];
                ExternalInterface.call("window.open('" + url + "','PopUpWindow','width=" + dimensions[0] + ",height=" + dimensions[1] + ",toolbar=yes,scrollbars=yes')");
            } else {
                // Use JS to bypass popup blockers if ExternalInterface is available
                var window:String = linkWindow == "_popup" ? "_blank" : linkWindow;
                if (ExternalInterface.available) {
                    ExternalInterface.call('window.open("' + url + '","' + window + '")');
                } else {
                    //request a blank page
                    navigateToURL(new URLRequest(url), window);

There now you can use these and link them into buttons for your sharing pleasure.
You can view an example here: http://www.netgfx.com/trunk/social/