[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.

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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

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

large-banner

– 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

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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'
      byteArray.compress();
      var enc:Base64Encoder = new Base64Encoder();  
      var b64;
      enc.encodeBytes(byteArray);
      // 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 <s:Image/> or any other component.


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

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

Enjoy!

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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);
}

enjoy!

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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.graphics.beginFill(0xff00ff,1);
circ.graphics.drawCircle(0,0,6);
circ.graphics.endFill();
circ.x = -10;
circ.y = 80;
stage.addChild(circ);

mc = stage.getChildByName('mc');

var button:Sprite = new Sprite();

button.graphics.beginFill(0xffeecc,1);
button.graphics.drawRect(0,0,30,30);
button.graphics.endFill();
button.x = 10;
button.y = 10;
button.width = 30;
button.height = 30;

button.addEventListener(MouseEvent.CLICK,resetLines,false,0,true);

createNodes();
}

Now we create the lines and the circles between them:
<code>
private function createNodes()
{
var circ = new Sprite();
for(var i=0;i {
circ = new Sprite();
circ.name = 'obj'+i;
circ.graphics.beginFill(0xff0000,1);
circ.graphics.drawCircle(0,0,3);
circ.graphics.endFill();
circ.x = i*100;
circ.y = 80;
stage.addChild(circ);
point_mcs.push(circ);
}

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


function dragMe(e:Event){
      TweenMax.killAll();
      var object = e.target;
      object.startDrag();
      stage.addEventListener(MouseEvent.MOUSE_MOVE, update)
    }
    
    function stopDragMe(e:Event):void{
      TweenMax.killAll();
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, update)
      stopDrag();
      mc.x = point_mcs[0].x;
      mc.y = point_mcs[0].y;
      TweenMax.to(mc,5,{bezierThrough:bezierPoints});
    }  
    
    function update(e:Event):void{
      mc.x = point_mcs[0].x;
      mc.y = point_mcs[0].y;
      createBezierPointsObject();
      updatePath();
    }

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];
        if(i!=0){
          bezierPoints[i] = {x:curPoint.x, y:curPoint.y};  
        }
        xA.push(curPoint.x);
        yA.push(curPoint.y);
      }
    }
    
//updating the path as we drag the nodes.
    function updatePath(){
      
      this.graphics.clear();  
      
      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;
      while(pointCount<bezierObj["x"].length)
      {
        this.graphics.curveTo(bezierObj.x[pointCount][1], bezierObj.y[pointCount][1],bezierObj.x[pointCount][2],bezierObj.y[pointCount][2]);
        pointCount++
      }
      
    }

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

createBezierPointsObject();
updatePath();
}

Download the project for Flash Builder here:
Bezier

View Example here:
DEMO

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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:

RGBaZR

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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.

Enjoy!

Facebooktwittergoogle_pluspinterestlinkedin
linkedin

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:

[cc lang=”Actionscript”]
// FACEBOOK
private function shareFB(e:Event):void
{
openPage(‘http://www.facebook.com/sharer/sharer.php?t=A+cool+video&u=’+escape(“http://flepstudio.org/utilita/VideoPlayer/IronMan2.mov”),”_popup”);
}

// TWITTER
private function shareTwitter(e:Event):void
{
openPage(‘https://twitter.com/intent/tweet?source=webclient&text=A+cool+video%3A+’+escape(“http://flepstudio.org/utilita/VideoPlayer/IronMan2.mov”),”_popup”);
}

// 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
{
openPage(“http://www.stumbleupon.com/submit?url=”+escape(videoInfo.videoLink)+”&title=”+escape(videoInfo.videoTitle));
}

// GOOGLE +
private function shareGoogle(e:Event):void
{
openPage(“https://m.google.com/app/plus/x/?v=compose&content=”+escape(videoInfo.videoLink),”_popup”);
}

// LinkedIn
private function shareLinkedIn(e:Event):void
{
openPage(“http://www.linkedin.com/shareArticle?mini=true&url=CONTENT-URL&title=”+escape(videoInfo.videoArtist)+”&summary=”+escape(videoInfo.videoArtist)+”&source=”+escape(videoInfo.videoTitle),’_popup’);
}

// DIGG
private function shareDigg(e:Event):void
{
openPage(“http://digg.com/submit?phase=2&url=”+escape(videoInfo.videoLink)+”&title=”+escape(videoInfo.videoTitle)+”&bodytext=”+”+”&topic=”+escape(videoInfo.videoArtist));
}

//BEBO
private function shareBebo(e:Event):void
{
openPage(“http://www.bebo.com/c/share?Url=”+escape(videoInfo.videoLink)+”&Title=”+escape(videoInfo.videoTitle),’_popup’);
}

//ORKUT
private function shareOrkut(e:Event):void
{
openPage(“http://www.orkut.com/FavoriteVideos.aspx?u=”+escape(videoInfo.videoLink),’_popup’);
}

//REDDIT
private function shareReddit(e:Event):void
{
openPage(“http://www.reddit.com/submit?url=”+escape(videoInfo.videoLink),’_popup’);
}

// DELICIOUS
private function shareDelicious(e:Event):void
{
openPage(“http://www.delicious.com/save?v=5&jump=close&url=”+escape(videoInfo.videoLink)+”&title=”+escape(videoInfo.videoTitle));
}

// MYSPACE
private function shareMySpace(e:Event):void
{
openPage(“http://www.myspace.com/Modules/PostTo/Pages/?t=”+escape(videoInfo.videoTitle)+”&c=”+escape(videoInfo.videoArtist)+”&u=”+escape(videoInfo.videoLink)+”&l=”+escape(videoInfo.videoLink),’_popup’);
}
[/cc]

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).

[cc lang=”Actionscript”]
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);
}
}
}
[/cc]

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/
Enjoy!

Facebooktwittergoogle_pluspinterestlinkedin
linkedin