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

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

Flex 4.5 add Icon to Buttons with AS3

This has changed since the pre-release and I thought I should mention it, because Icons on buttons are awesome.
So if you have set your button with mxml the property icon is right there, however if you want to dynamically create a button with an Icon with AS3 script you will have to declare it like this:

var Btn = new Button();
Btn.setStyle("icon","assets/icon.png");

As you see Icon property is now a style rather than a property.

Enjoy!

OSMF Strobe Media Player into Flex Mobile Project (Hero)

I have worked with Strobe media player before and it is a nice player with many features and allows a great level of customization if done properly.

So I’ll explain how to import the Strobe Media player into your Mobile Flex builder Projects successfully and create a dynamic Stream with it.

First Download Strobe Media Player: http://sourceforge.net/projects/smp.adobe/files/ (currently I work with 1.5.1)

Export the contents into a folder.

Create a new Mobile Project on Flash/Flex Builder

Copy from the Strobe Media player folder the “src/player/StrobeMediaPlayback/src” and from the same folder the “/assets” folder

Also copy from “/StrobeMediaPlayback_1.5.1-full/src/framework” the OSMF.swc

and place them on the src folder of your project. Refresh the folder tree from Flash/Flex builder.

Place the OSMF.swc into your lib folder.

Now on to some Configurations:

On the Project/Properties

On Build Path/Library Path add the assets.swc from the assets folder

On Compiler arguments add: -define CONFIG::LOGGING false -define CONFIG::FLASH_10_1 true

 

At last Coding time!

Create a new View component, open a fx:Script tag and enter the following:

import mx.core.UIComponent;

import spark.components.Button;
import spark.components.Group;

public var $playerInstance:StrobeMediaPlayback;
var grp:Group = new Group();
protected function init(event:Event):void
{

_stage = systemManager.stage;
_stage.align = StageAlign.TOP_LEFT;
_parameters  =
{
src:"http://osmf.org/dev/videos/cathy1_SD.mp4"
, controlBarMode:"docked"
, controlBarAutoHide: true
, autoPlay: true
, playButtonOverlay:true
, showVideoInfoOverlayOnStartUp: true
};

var playerInstance:StrobeMediaPlayback = new StrobeMediaPlayback();
playerInstance.initialize(_parameters, _stage, systemManager.loaderInfo, null);
$playerInstance = playerInstance;

var ui:UIComponent = new UIComponent();
ui.addChild($playerInstance as DisplayObject);

grp.percentWidth = 100;
grp.percentHeight = 100;
addElement(grp);
grp.addElement(ui);

}

private var urlLoader:URLLoader;
private var urlRequest:URLRequest;
private var loader:Loader;
private var _stage:Stage;
private var _parameters:Object;
/* static */
private static const ALLOW_LOAD_BYTES_CODE_EXECUTION:String = "allowLoadBytesCodeExecution";

function emptyCache()
{
$playerInstance.player.pause();
grp.removeAllElements();
this.destructionPolicy = "auto";
}

Note!

Make sure to call init() on ViewActivate, or CreationComplete event. Also I recoment to assign on ViewDeactivate the emptyCache() function otherwize the sound of the video might keep on playing…

As a side note here, its better to create components in Actionscript even spark ones, than in mxml at least at this point where Flex Hero framework is still in Beta.

So thats it, now you have Strobe Media Player in your Mobile Application, especially now with 10.2 and stage video that focuses on low CPU consumption its essential for any mobile application with a video player.

!Important: In case you are not viewing a controlBar there is a chance that the default ActionBar is pushing the ControlBar downwards, so if that is the case try a different percentage for grp.percent=90, or disable the ActionBar -> set actionBarVisible = false in the View component properties.

Enjoy!

IconFox new Application

Icon fox is a desktop application, for organizing and managing icons and assets, it offers simplicity as the user can directly drag and drop the desired assets to a folder, or view it with the system default viewer.

Categories open directly their assigned folders or a custom search tool also exists.

Check it out here: http://www.netgfx.com/iconfox

Please post any bugs or problems you encounter as well as suggestions for future releases.

Adobe Air , export data to .ics and import to google Calendar

Let’s assume you have a dataGrid with some data, and they are categorized by date. Then you wanted to import those data/notes to google calendar (create one and name it “sample Calendar”, or change the calendar name below to match one of your already created calendars.

note:

/* This functionality is implemented in my Calendar Application, and the source code including these functions will be available in the following days at: Google Code
*/

Here is how:

first of you will need the place to save the file…

public function saveAs():void

{

var docsDir:File = File.documentsDirectory;

var typeArr:Array=[“.ics”,”.txt”];

try

{

docsDir.browseForSave(“Save As: || Type only name without extension”);

docsDir.addEventListener(Event.SELECT, saveICS);

}

catch (error:Error){

trace(“Failed:”, error.message);

}

}

//then you will need the google Calendar .ics structure

public function saveICS(event:Event)

{

var newFile:File = event.target as File;

newFile.nativePath +=”.ics”;

var arr:Array=[];

var FINAL_STR:String =””;

/*initialization options, no need to recreate. use as is. */

arr[0]=

[
“BEGIN:VCALENDAR”+”\n”+

“PRODID:=//Google Inc//Google Calendar 70.9054//EN”+”\n”+

“VERSION:2.0″+”\n”+

“CALSCALE:GREGORIAN”+”\n”+

“METHOD:PUBLISH”+”\n”+

“X-WR-CALNAME:sample Calendar”+”\n”+

“X-WR-TIMEZONE:Europe/Athens”+”\n”

];

//to go through the whole dataGrid

for (var i=1;i {

arr[i] = [

“BEGIN:VEVENT”+”\n”+

“DTSTART:”+dg.dataProvider[i-1].year+formatMonth(reverseMonth(dg.dataProvider[i-1].month))+formatMonth(dg.dataProvider[i-1].date)+”T”+formatTime(‘s’,dg.dataProvider[i-1].time)+”\n”+

“DTEND:”+dg.dataProvider[i-1].year+formatMonth(reverseMonth(dg.dataProvider[i-1].month))+formatMonth(dg.dataProvider[i-1].date)+”T”+formatTime(‘e’,dg.dataProvider[i-1].time)+”\n”+

“DTSTAMP:20100123T152831Z”+”\n”+

“UID:”+”\n”+

“CREATED:20100123T101105Z”+”\n”+

“DESCRIPTION: “+String(stripHtmlTags(dg.dataProvider[i-1].comments).replace(/”/g,” “))+”\n”+

“LAST-MODIFIED:20100123T1001105Z”+”\n”+

“LOCATION: – “+”\n”+

“SEQUENCE:0″+”\n”+

“STATUS: CONFIRMED”+”\n”+

“SUMMARY:”+String(dg.dataProvider[i-1].comments)+”\n”+

“TRANSP:OPAQUE”+”\n”+

“END:VEVENT”+”\n”

];

FINAL_STR += arr[i];
}
arr[dg.dataProvider.length] =
[
“END:VCALENDAR”
];

// Save the file

var stream:FileStream = new FileStream();
stream.open(newFile, FileMode.WRITE);
stream.writeUTFBytes(arr[0]+FINAL_STR+arr[dg.dataProvider.length]);
stream.close();
}

/* some formation functions. depends on the format you use on the dataGrid, you might or might not need them. */

public function formatTime(pos,str:String):String
{
var timeArr:Array=[];
var hh = “”;
var mm = “”;
var ss = “00”;
var FINAL_TIME;

timeArr = str.split(“–“);
if (pos == “s”)
{
hh = String(timeArr[0]).slice(0,2);
mm = String(timeArr[0]).slice(-2);

FINAL_TIME = hh+mm+ss;
}
else if(pos == “e”)
{
hh = String(timeArr[1]).slice(0,2);
mm = String(timeArr[1]).slice(-2);

FINAL_TIME = hh+mm+ss;
}
return FINAL_TIME
}

public function formatMonth(str)
{

if (Number(str)<10) str = "0">