jan 05

Here is something i was thinking for along time : capturing a flash movie area and save it to video file.

Hopefully I found a great AIR example to do this on : http://www.zeropointnine.com/blog/simpleflvwriteras-as3-class-to-create-flvs/
This application saved bitmapdatas to FLV video file.

I turned it into non-AIR application, and i took the opportunity to add several improvements:

  • easier constructor creation (simply specify displayobject to capture and video fps)
  • memory optimization
  • faster video computation
  • internal capture management
  • capture area parameter

In the example captured area is inside a movieClip, and captured FLV is saved to local disk.

Usage :

// capture screen_mc clip , with 20fps framerate
// note that clip bounding box will be used as capturing area
var _myRecord : FLVRecord = new FLVRecord(screen_mc, 20);

// start recording (or resume capture)
_myRecord.start();

// stop recording (or pause capture)
_myRecord.stop();

// you can use clean() to start a new record with start();
_myRecord.clean();

// and finally get the FLV raw data of FLV to save it or send it to PHP script
var _file : FileReference  = new FileReference();
_file.save(_myRecord.flvRawData, "video.flv");

And here is source download link.

BE CAREFUL WITH MEMORY !!!!!

FLV files are quite huge, so use it wisely !!!
To reduce FLV file size, lower FPS parameter and restrict capture area :

// capture screen_mc clip , with 15fps framerate, and restricted capturing area
var area : Rectangle = new Rectangle(92,9, 160,224);
var _myRecord : FLVRecord = new FLVRecord(screen_mc, 10, area);

// survey FLV size if it's going to big
var flvSize : Number = int(_myRecord.flvLength/100000)/10; // size in megabytes
if (flvSize>35) trace("FLV size is larger than 35Mo);

Enjoy.

nov 30

Here is a little experiment with the Google TTS (Text To speech) API.

As far as i looked, there no limitation for using this API, so enjoy :

NB : as a bonus, here is a funny use of TTS in german language :)

Here is a short code to use my TextToSpeech class :

var _txt2Speech : TextToSpeech = new TextToSpeech();

// and simply call a new text to be said
// passing text + language to be used
_txt2Speech.say("bla bla bla", "en");

And here is source download link.

Have fun !

NB : for unknown reasons, the example is not working under Chrome browser...

nov 26

Here is a little experiment around the exciting Open Kinect project :
http://openkinect.org/wiki/Main_Page

My idea was to use the as3-server that comes with the git archive.

Here are the several steps I've been through to get to this raw result :
- compilation of the as3-server on OSX (yesterday version was finally working)
- turned AS3 singletons examples to exploitable classes (to instantiate sockets individually and the get 3 streams at the same time)
- found that Flash has to get the policy file from server before init the next sockets (i created a queue for sockets)

And here is the result :

Upper image results from the RGB stream.
Bottom image is the Depth stream.
Extra data are shown in the white box.

I hope to have time soon and go deeper in all these data streams and create something fun.

oct 12

Feel free to visit my fresh new personal site !!!

http://www.lecrabe.net

Credits:
GFX : Kassad / www.frak.fr
Code: well, hum me...

jan 19

Recently i made a quick visual effect including the latest Flash Player 10 classes : Vector & Vector3D classes.

As the Vector and Vector3D classes are well optimized, I wanted to optimized my own loops.

So came again the question : "What is the most optimized loop system for these classes ?"

So i wrote a quick "while loops" performance test where i use a huge Vector array of Vector3D instances where i tried several systems.

I firstly thought that there was no way using the "for loops", but i read this quite interesting article :

http://www.experts-exchange.com/articles/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/ActionScript/20-Tips-to-Optimize-your-ActionScript.html

and i finally put the for loop test as the last test.

Each test performs a vector crossproduct on each Vector3D, and this for 2 millions vectors !!!

clear here to start the while-loop test

I was used to coding my loops with the first loop test :

i = vect.length;
while(i--){}

but apparently the most optimized loop on my mac (imac 27") should be the 3rd test :

i=vect.length;
while (--i>=0) {}

For my computer (Mac/Firefox) each test of the benchmark is almost the same, even the "for loop" which is quite efficient.

But I look closely, the fact is was using the less optimized while loop (according to this test)...

It's up to you to test your own computer and may choose one of these loop.

jan 13

As i was installing Alchemy toolkit for some experiment, i was first stuck in installing the Flex 3.5 SDK : to get the flex sdk linked to your system you are supposed to add the "flex/bin" directory in your system path.

Looking on the web, the ".profile" file has to be changed, but i couldn't find it... the reason : I had no ".profile" file on my system....

So if you don't have any ".profile" file in your home directory (your nickname directory), here are the steps to follow :

1) First of all, you may want to show hidden files on your mac to see exactly what you do,  to do so type the following lines in your terminal:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

  • change TRUE/FALSE to activate/deactivate the option
  • killall Finder will close all finders as it has to be restarted

2) Then create a new file in TextEdit for example and add this :

export PATH=$PATH:/usr/local/bin:/Applications/flex_sdk_3.5/bin

(in my example I unzipped the flex sdk in my Applications generic folder)

This will add the flex bin folder path in your system path.

3) Now save the file as ".profile" in your your home directory

4) Now you have to load/reload your ".profile" to make it active, type this in the terminal :

open a new Terminal so that it opens in your home directory and type:

. ./.profile

this will reload the file

5) test if your path has been integrated in the $Path variable, type

echo $PATH

6) Final step, check if Flex SDK is now available :

just type "adt" in your terminal and you should not have any error

That's it, if you want to check if your path

déc 16

The facts :

As you may know, some tools like firebug helps you tracing incoming and outcoming data between flash and scripts, even if you use POST data.

See below how firebug can trace all variables sent through the POST data :

firebug tracing

firebug tracing

So i tried to figure out how to implement a crypted system to secure (a little bit more) these data, with an encryption key if possible.

I found the useful project on the web : as3crypto project

Thanks to this class, you can crypt/decrypt in flash but as far as i looked the sources, there was no information about crypt/decrypt on php side.

But i found another message in a forum where a php code was given, so i mixed both to provide you a simple way to set both sides.

In my example, flash send some data to php using crypted message and PHP answer another crypted message (+ the original decrypted flash message for verification):

pnm_preview


  • Using the php class : cryptlib.php

  1. create an instance of the class, and call the init with the crypted key as parameter
  2. decrypt the sent message (using POST object)
include_once "lib/cryptlib.php";

// init a new instance of Crypto Class
$crypto = new Crypt;

// init with the encryption key
$result = $crypto->init("PASSWORD");

// get the POST data
$messagefromflash = $_POST ["message"];

// decrypt data
$decrypted_messagefromflash = $crypto->decrypt(utf8_decode($messagefromflash));

but you can also send back crypted data to flash using the "encrypt" method

// return a crypted result to flash
$resultmsg = "Ok, i received your data, everything is fine !";
echo "result=".$crypto->encrypt(utf8_encode($resultmsg));
  • Using the as3 class : CryptoCode.as

  1. in your main class, create an instance of the CryptoCode class that will crypt/decrypt your data.
  2. call the init method with the same key as PHP (just like PHP code)
  3. then call "encrypt(s:String)" or ""decrypt(s:String)" methods through your crypto instance
// instance of crypto class
 private var _crypto : CryptoCode;
 public var myLoader : URLLoader;

// create instance with encryption key
 _crypto = new CryptoCode("PASSWORD");

// send crypted string to php script
 var variables : URLVariables = new URLVariables();
 variables.message = _crypto.encrypt(tosend_in.text);

// create request with POST method
 var request : URLRequest = new URLRequest("http://www.lecrabe.net/wordpress/demo/crypt/scripts/testcrypto.php");
 request.method = URLRequestMethod.POST;
 request.data = variables;

 // send request
 myLoader.load(request);

If you want to get the whole example, please download the sources.

Enjoy.

sept 29

It's been a long time since i post a new article, and it's a brand new start !!!

The blog turned into wordpress blog, and here is a handy tool I wrote for my personal use in the first place :

Mac File Cleaner is a tool for people who work on both Mac and Windows platforms.

Every time a mac user send files to a windows user, many hidden files appears in the windows system : "._*" files and ".DS_Store" files.

These annoying files may be a problem as in my personal project, so MFC will solve this problem in 2 steps :

1) place the MFC executable file in the root folder where you want to remove those mac files

2) run MFC, and it will recursively remove every mac files

STEP 1 :

MFC executable

The mac files cleaner is placed at the root of the project.

STEP 2:

snap2

MFC indicates where the recursive operation will start from, then click CLEAN button

STEP3 :

snap3

MFC deletes all mac files recursively and shows you the scanned folders and deleted files.

If wrong files are deleted, they may be found in the system trashcan.

Download Mac Files Cleaner

Enjoy.

août 06

Thanks god eclipse has its own undelete option !!!

Continue reading »

août 05

Here is a little trick that may help you to target items on scene right after a gotoAndStop/gotoAndPlay

Continue reading »