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


Simple Loader with AS3 and TweenMax

This a loader that I created for my OSMF-based player. This is lightweight and simple to use.
Colors and shapes can easily be customized, text could also be included and event animated to match blocks.

The creation function, simple drawing.

[cc lang=”actionscript”]public function createLoader(bgColor:uint=0x2e2e2e):void
this.x = 0;
this.y = 0;
bg = new Sprite();
var gap:Number = 45;
var block:Sprite;

for(var i:int = 0;i<6;i++){ block = new Sprite(); block.graphics.beginFill(0xffffff,1); block.graphics.lineStyle(1,0x7e7e7e,1,false); block.graphics.drawRect(gap+(20*i),40,9,22); block.graphics.endFill(); bg.addChild(block); } this.addChild(bg); tint(); [/cc] And the function that handles the animation, it applies colorization to each block in order then calls it self with the index increased by one. [cc lang="actionscript"] private function tint(value:Number=0):void { var length:Number = bg.numChildren; var indexItem:Number; for(var i:int = 0;ilength-1) { indexItem = 0; } else { indexItem = value; } TweenMax.to(bg.getChildAt(indexItem), .2, {colorMatrixFilter:{colorize:0x3399ff, amount:1.2, contrast:1, brightness:1, saturation:1, hue:50}, onComplete:function(){ TweenMax.to(bg.getChildAt(indexItem), .6, {colorMatrixFilter:{colorize:0xffffff, amount:1}, ease:Quad.easeInOut}); tint(indexItem+1); }}); }[/cc] The release version is a mere 20kb file. Download the source here: UILoader

View Example here: UILoader-Demo


Components Factory from XML/AS3

In this post we will create Video and Image components by using only an XML file and AS3 code. Finally we will place all these Components into a Grid Gallery.

This approach has many benefits as it will render more smoothly in mobile devices and tablets as mxml code is a bit heavy even with the latest Flex Hero build.

This is the XML structure that we will use:

<item target=”assets/img.jpg” type=”image”/>
<item target=”http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-960.mp4″ type=”video”/>
<item target=”http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-960.mp4″ type=”video”/>
<item target=”http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-960.mp4″ type=”video”/>
<item target=”http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-960.mp4″ type=”video”/>
<item target=”assets/img.jpg” type=”image”/>
<item target=”assets/img.jpg” type=”image”/>
<item target=”assets/img.jpg” type=”image”/>

The MXML Tile component (this could also be AS3 code)

<s:TileGroup id=”grid” x=”0″ y=”0″  creationComplete=”buildItemsFromXML()”>

Now some AS3 code:

we will create the loader function

[cc lang=”actionscript”]

private function buildItemsFromXML()
var xmlCall:XMLService = new XMLService();

//The magic happens into the success response function

function resultResponse(evt:ResultEvent)
itemArray = new Array();
var result = evt.result as XML;
var xml = result.items.elements(“*”);
for each(var item in xml) //Parse all elements of the XML
if(String(item.@type).toLowerCase()==”video”) // Create a VideoDisplayComponent
var vid:VideoDisplay = new VideoDisplay();
vid.source = String(item.@target);
vid.autoPlay = false;
vid.scaleMode = “stretch”;
vid.width = itemsWidth;
vid.height = itemsHeight;
vid.verticalCenter = 0;
vid.horizontalCenter = 0;
else if(String(item.@type).toLowerCase()==”image”) //Create a spark Image component
var img:Image = new Image();
img.source = String(item.@target);
img.width = itemsWidth;
img.height = itemsHeight;
img.verticalCenter = 0;
img.horizontalCenter = 0;
else if(String(item.@type).toLowerCase()==”videoplayer”)  // Create a VideoPlayer component
var vidp:VideoPlayer = new VideoPlayer();
vidp.source = String(item.@target);
vidp.autoPlay = false;
vidp.scaleMode = “stretch”;
vidp.width = itemsWidth;
vidp.height = itemsHeight;
vidp.verticalCenter = 0;
vidp.horizontalCenter = 0;

placeItems(); // The next function that will place the items into the grid


Now we place all elements into the Tile Gallery

[cc lang=”actionscript”]
function placeItems()
//add all elements into the grid,
for each(var item in itemArray)
var grp = new Group(); //We prefer the Group component because it makes it easy to position elements inside

And we are done! Now you have your own components factory build only by XML and AS3 code.

View an Example Here: http://www.netgfx.com/GridGallery/