Search code examples
actionscript-3movieclip

Send a movieclip with socket


I am trying to develop, online drawing application like iSketch. But dont write, real time drawinn part.

I am tried this way: The user draws graphic on a movieclip (movieclip name as "board" and it's size 396*318) And than i am convert this movie clip to BitmapData, getting all pixel color data (as hexadecimal) by getpixel method. Than send this data to server(with socket), server resend to all users, and the client codes, draw a bitmapData by setPixel method.

At this point i have a problem. My string (holding the color data) contains 745,550 character, this is 162 word page, and too big string. What can I do for better performance?

My Codes:

        var rect:Rectangle = new Rectangle(258,203,GENIS,YUKSEK);
        // create BitmapData
        var bmd:BitmapData = new BitmapData(GENIS,YUKSEK,true,0);
        bmd.draw(board);

        var s:String = "";
        for (var i:int = 0; i< 396; i++)
        {
            for (var t:int = 0; t< 318; t++)
            {
                var r:uint = bmd.getPixel(i,t);
                s +=  r.toString(16)+ "-";

            }
        }

Note: I'am note use any translator tool, sorry for my bad english.


Solution

  • You have to compress it , using JPG or PNG like 'bitmapdata.com' says. You can also try save BitmapData directly to ByteArray and than send (sometimes it have similar performance , depends on graphics ) , but I think best You can do is send vector graphics or send users drawing steps , that would be fastest way.

    edit : use native bitmapdata functions like get/set pixels and operate on ByteArray , You will get better performance.