AMFPHP and mbstring

These days I was working on a flex 2/amfphp project and I discovered a very strange issue accidentally.
With PHP 5.2.4 installed both on local and remote server, the local amfphp works and the remote gave errors.

Connecting to the service browser I was receiving the error “Channel.Ping.Failed” error and investingating a bit more in the fault message I discovered that the source error was:

The class {Amf3Broker} could not be found under the class path {/var/htdocs/amfphp/services/amfphp/Amf3Broker.php}

and the Amf3Broker php class does not exists anywhere in amfphp! But in the Actions.php file on line 78 I found this:
if(!$handled)
{
$uriclasspath = "amfphp/Amf3Broker.php";
$classpath = $baseClassPath . "amfphp/Amf3Broker.php";
$classname = "Amf3Broker";
$methodname = "handleMessage";
}

That’s the strange thing because the $handled variable should be true ’cause usually the first request sent by flash is a $messageType = “flex.messaging.messages.CommandMessage”. So I continued in my investigation logging all the messages that php was receiving.
So at the end I discovered that amfphp didn’t deserialize the amf data correctly! All the packet were corrupted (that’s why $messageType wasn’t handled), all the strings were not correctly parsed.
Finally I discovered the reason. It’s because mbstring.
The only difference between the remote server and the local server is the php.ini setting about mbstring overload and the others mbstring settings.
The remote server has mbstring.func_overload = 2, that means all the strings functions are affected and that’s why the amfphp methods were returing corrupted data.
In fact I just changed this method into AMFDeserializer.php:
function readBuffer($len)
{
$data = substr($this->raw_data,$this->current_byte,$len);
$this->current_byte += $len;
return $data;
}

into:
function readBuffer($len)
{
$data = "";
for($i = 0; $i < $len; $i++) { $data .= $this->raw_data{$i + $this->current_byte};
}
$this->current_byte += $len;
return $data;
}

and the original error disappeared! Obviously I got other errors later, that’s because there are many other string functions in amfphp.. but at least I found the cause.

In fact, removing the mbstring.func_overload in the php.ini everything worked again!

Adobe Image Foundation

Everyone already knows about the new Flash player 10 (Astro) features that adobe presented at MAX, and above all the new image processing language (Hydra) that it will support in the future.

Today I finally found a couple of hours to play with AIF, even if no more because of my limitations knowledge of image processing algorithms 🙂
In fact I was able to broke different times my video card driver (with a panic black screen)!

Anyway after all I did just a couple of experiments trying to convert a couple of scripts I already did using the old flash 9 bitmapdata filters..


kernel Snn
{
parameter float size
< minValue: 0.0; maxValue: 8.0; defaultValue: 2.0; >;
parameter int step
< minValue: 1; maxValue: 10; defaultValue: 1; >;
void evaluatePixel(in image4 src, out pixel4 result)
{
pixel2 coord = outCoord();
pixel4 valueC = sampleLinear(src, coord);
float theStep = float(step);
float2 point = float2(0.0,0.0);
float x = 0.0;
float y = 0.0;
float count = 0.0;
pixel4 sum = pixel4(0.0, 0.0, 0.0, 0.0);
pixel4 valueA;
pixel4 valueB;
for( x = - size; x < size; x+= theStep)
{
for(y = -size; y < size; y+= theStep)
{
valueA = sampleLinear(src, pixel2(coord.x + x, coord.y + y));
valueB = sampleLinear(src, pixel2(coord.x - x, coord.y - y));
if ( any(lessThan(abs(valueC - valueA), abs(valueC - valueB))))
{
sum = sum + valueA;
} else {
sum = sum + valueB;
}
count = count + 1.0;
}
}
result = sum/count;
}
}


kernel Websafe
{
parameter float value
< minValue: 0.0; maxValue: 500.0; defaultValue: 10.0; >;
void evaluatePixel( in image4 src, out pixel4 result)
{
result = sampleLinear(src, outCoord());
result = (floor((result*255.0)/51.0) * 51.0)/255.0;
}
}

As you can see it’s nothing new, they’re just my first steps in this new language.. don’t spend much time on these example, look at the coolest examples shown in the Hydra gallery instead!

Microsoft to release .NET libraries source code

Well, it seems that Microsoft will release the .NET libraries (not all, but it seems the most relevants ) source code with the next release of Visual Studio 2008 late this year.

This will be useful indeed while debugging in VS, but also it would be very interesting to look into the source code to view how they did it, expecially the Windows Form related part.. (..but what about Silverlight? :))

Read more here: http://weblogs.asp.net/scottgu/…framework-libraries.aspx

SharedObject reader plugin for FD3

In the past week I was working on the SharedObject plugin for FlashDevelop 3.
First I just made a port of my previous sepy sharedobject reader python code into C#, but then for the new AMF3 sharedobject encoding I found this java class very useful.
By the way, after coding and coding.. I finally managed to create a good solution (ok, I have to test it a lot again…).
You can find the plugin here: http://code.google.com/p/fdplugins

But the interesting thing I found was another!
Flash does not read the sharedojects correctly (at least the amf0 ones)!

To reproduce this bug follow these steps:

Create a new document (flash8 / as2)
– Add this code in the timeline:
var so:SharedObject = SharedObject.getLocal("flash8", "/");
so.clear();
so.data.obj1 = new XML("");
so.data.obj2 = new Date();
so.data.obj3 = so.data.obj2;
so.data.obj4 = {a:1, b:so.data.obj1, c:[1,2,3], d:so.data.obj2};
so.data.obj5 = so.data.obj4.c;
so.flush();

you will see this in the debug view variables:
Variabile _level0.so = [oggetto #1, classe 'SharedObject'] {
data:[oggetto #2, classe 'Object'] {
obj1:[oggetto #3] {
;
},
obj2:[oggetto #4, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
obj3:[oggetto #4, classe 'Date'],
obj4:[oggetto #5, classe 'Object'] {
d:[oggetto #4, classe 'Date'],
c:[oggetto #6, classe 'Array'] [
0:1,
1:2,
2:3
],
b:[oggetto #3],
a:1
},
obj5:[oggetto #6, classe 'Array']
}
}

ok, now remove all the code you just written and leave just this line:
var so:SharedObject = SharedObject.getLocal("flash8", "/");
and see the variables list again, you will see this:
Variabile _level0.so = [oggetto #1, classe 'SharedObject'] {
data:[oggetto #2, classe 'Object'] {
obj1:[oggetto #3] {
;
},
obj2:[oggetto #4, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
obj3:[oggetto #5, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
obj4:[oggetto #6, classe 'Object'] {
d:[oggetto #7, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
c:[oggetto #8, classe 'Array'] [
0:1,
1:2,
2:3
],
b:[oggetto #6, classe 'Object'],
a:1
},
obj5:non definito
}
}

they are different! (both data.obj5 and data.obj4.b changed)

For what I understand during my experiments it seems that flash does not write into its internal references table the XML objects while reading back the file and so next time it open the sharedobject all the references after the xml are broken or just they point to a different object.

FDTracer

Click to see a preview
Andrew has just posted on his blog FDTracer, a FlashDevelop plugin which does more or less the same of my Firefox FlashTracer plugin.
Once you’ve installed the .dll plugin remember to change the plugin settings and insert the correct path of your flash player log path. ( Read more here )

Remember also that you need, like for FlashTracer Firefox addon, a debug version of flash player. It can be downloaded here


					

Flex Camp, Milan 19th October 2007

Flex Camp is a series of conferences designed to help you understand more about Adobe Flex and Adobe AIR“, first started by flex.org.

This is the first flex Camp conference in Italy, scheduled on 19th October 2007 in Milan.

– Actionscript 2 to Actionscript 3 migration
– Flex and Flash CS3 integration
– Flex Builder 3. A first look
– Flex and AIR

For more details and to participate please visit:  http://flex.actionscript.it…/title=Pagina_principale

FlashDevelop 3, unsorted plugins

Last week I started a new Flash project, and unluckily it was an ActionScript 2 project!…
Oh, It was so long time since I last wrote as2 code… I didn’t remember it’s so boring and poor . Actionscript 3 it’s a complete different world compared to as2, now I can understand this better. BTW, I decided to use for this project FlashDevelop 3. I still remember the days when they first announced the birth of this project (those days when I still was writing sepy…), but I never really try it in depth.
After 2 days using it I was fully satisfied of my choice, this is really an awesome project!

But.. because I’m too curious, I wanted to take a look also at the source code.. just to a look. Also because I never coded in C#.
Anyway, after a couple of days I found that making plugins wasn’t so hard, even if for a c# newbie like me (and also thanks to some tip from Philippe), and so I wrote down some testing plugins. they’re not killer plugins at all, just simple program addons.

1. SourceOptions: this is the very first I did and in fact it doesn’t do anything special. In AS2 and AS3 files it adds to the scintilla contextual menu three more options: “organize imports” (similar to the  one in flex), “add getter/setter method” and “add accessor method” (when you click on a class variable)

2.  Bookmarks panel: This create a docking panel displaying all the current opened files and keep updated their bookmarks.

3. Flash API panel: Similar to the one included in the Flash IDE. Just give (in the plugin settings) the path (one or more) of the xml included in the ActionsPanel flash directory and it will display the full list of all the language available actions/methods/classes. Double click on an item will insert the command in the document text giving also the description of the selected command in a tooltip.

Tip: those xml file can be found in a directory like this:

C:\Users\sephiroth\AppData\Local\Adobe\Flash CS3\en\Configuration\ActionsPanel\ActionScript_3\ActionsPanel_3.xml

4.  ASClassWizard: It overrides the “New Class” project menu command and displays a wizard dialog for creating a new ActionScript 2/3 class. Give the package, the classname, super class, implementing interfaces and it will create your class.

Note: Remember that those plugins work only with the last 1769 FlashDevelop 3 build, available here:

http://www.flashdevelop.org/community/viewtopic.php?t=1734

Project Home at http://code.google.com/p/fdplugins with all the latest versions of these plugins and more plugins