vendredi 25 décembre 2015

as3 load serialize object from java servlet

First, sorry for my english. I was making a simple streaming program. To a first approximation I use a servlet in a server that recover a image from webcam connect it at this, and send the image to an java applet. That works fine, i recover correctly the image and show it into the applet. But the applets not are compatible with android, then, I build a android application that connect to the same servlet and recover a image like response of this, i show it in the mobile screen. Again, works fine. But now, I'm thinking in build a as3 application for not use separately a android application for mobile and a applet for pc users.

The code of my servlet that send the image is this:

ObjectOutputStream salida = new ObjectOutputStream(response.getOutputStream());

where imageInByte is an java byte[]

the code of my as3 project is:

main class:

public class Main extends Sprite {

    public function Main() {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);

    private function init(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        addChild(new WebCam());


webcam class:

public class WebCam extends Sprite

    private var request:URLRequest = new URLRequest("http://localhost:8080/WebCamToAndroid/Respuesta?action=actualizar");
    private var loader:URLLoader = new URLLoader();

    public function WebCam()
        request.contentType ="application/x-java-serialized-object";

        loader.addEventListener(Event.COMPLETE, completeHandler);
        try {
            loader.dataFormat = URLLoaderDataFormat.BINARY; 
        } catch (error:Error) {


    private function completeHandler(event:Event):void {
        var bytes:ByteArray =;
        addChild(new ShowImage(bytes));



ShowImage class:

public class ShowImage extends Sprite
    private var loader:Loader;

    public function ShowImage(bytes:ByteArray=null) 
        loader =new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);

        if(bytes == null){
            loader.load(new URLRequest(""));
        } else {

    public function onImageLoaded(e:Event):void


Here it's the problem, I can't see anything, I think that the problem is in as3 application. I was reading into internet looking for a example that could be help me, but any code that I proved help me. What it's the problem? That I was wrong?


Aucun commentaire:

Enregistrer un commentaire