0

I have flex mobile client, and it takes java server byte[] as flash.utils.ByteArray, but when I want to use as a source of my bitmapImage compiler says that unknown type:

private function onResult3(event:ResultEvent,token:Object):void 
{
    if(event.result!=null)  
    {
        var Lder:Loader=new Loader();
        var ba:ByteArray=event.result as ByteArray;
        Lder.loadBytes(ba);// exception is thrown here
        doktorResim.bitmapData.draw(Lder);                  
     }  

}

Any help, suggestion?

Benoît Guédas
  • 801
  • 7
  • 25
Coenni
  • 197
  • 5
  • 16
  • What is the exception? Is 'ba' null after the conversion? Have you stepped through code? – JeffryHouser May 07 '12 at 16:49
  • ba is not null after conversion, it has length it's ok. I think the problem is that loader could not recognize the structure of ba. database is oracle, server sends as byte[] to flex mobile client's byteArray. – Coenni May 08 '12 at 06:10
  • What is the exception? Please provide the full stack trace. – JeffryHouser May 08 '12 at 14:04
  • Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type. – Coenni May 17 '12 at 11:42
  • Please show your java code too, may be byte array is not loading properly, you need to look in 3 places, 1) Java is loading all bytes from Oracle and 2) Java is writing all bytes to response stream and lastly 3) Flex is reading All bytes from Java without interuption. – Imran May 23 '12 at 06:17

1 Answers1

1

If Java is reading and sending bytes properly, then you need to wait for flex to load all bytes for thats use event complete of LoaderInfo see also Loader Class

var url:String = "http://www.helpexamples.com/flash/images/image2.jpg";
var urlRequest:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
loader.load(urlRequest);
addChild(loader);

function loader_complete(evt:Event):void {
    var target_mc:Loader = evt.currentTarget.loader as Loader;
    target_mc.x = (stage.stageWidth - target_mc.width) / 2;
    target_mc.y = (stage.stageHeight - target_mc.height) / 2;
}

Hopes that helps

Imran
  • 2,906
  • 1
  • 19
  • 20
  • The error is sth different. I have a byteArray as a result. And its size is the as in the java server. but when I call loader.loadBytes(resultBytes); the exception:"Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type." is thrown. And I could not find any solution to the problem so far. – Coenni Jun 02 '12 at 06:56
  • did you add event listener Complete, Also show your java code, can you able to Write File on Disk From DB using JAVA? – Imran Jun 02 '12 at 07:28
  • it is due to BlazeDs library which I use between Java Server and Flex mobile platforms. I read content of each byte array one is like "66 22 77 ..." in the flex side is sth stange like "BMá..." – Coenni Jun 02 '12 at 08:24
  • Yes, I have written. The problem is different. Loader does not recognize my byteArray as byteArray actually. Debugger does not go inside to onComplete event anyway. There is not any problem in Java Server code it just returns byteArray from Oracle table cell. – Coenni Jun 02 '12 at 08:27
  • public byte[] getHastaResim(String hastaTc) { String sql = "select r.resim from ha_hbys_resimler r where r.tckimlik_no ='" + hastaTc + "'"; byte s[] = null; ResultSet rst = null; try { try { rst = exQuery(sql); } catch (ClassNotFoundException ex) { Logger.getLogger(DbConnection.class.getName()).log(Level.SEVERE, null, ex); } rst.next(); s = rst.getBytes(1); } catch (SQLException ex) { System.out.print(ex.getMessage()); } return s; }//server code – Coenni Jun 02 '12 at 08:30
  • yes, I can show byteArray in Java application getting same byteArray, that's why I think its due to encoding problem. – Coenni Jun 02 '12 at 08:32
  • i thinks you are not reading bytes properly from Database in java, you can verify this by , read bytes from Database and Write image file on Disk, Are you able to do this and view proper image from written file? – Imran Jun 02 '12 at 09:44
  • I can use byteArray as an image source in java application using same server. but in flex application it is not possible because of serialization or decoding. – Coenni Jun 02 '12 at 09:51
  • try to write file on disk using byte Array from, asking just to make sure you are reading each and every byte in java from Database, before sending it to Flex. – Imran Jun 02 '12 at 09:56
  • '"-96T][´¼ºÑÝÛàöôâýúëüüãòóÛèéÙæçàðïëùøèóôèóôêòôìóõîóõ��öøðõ÷ðõ÷óõøóõøóõøóõøóõøóõøöõøöõøõõøõõøõõøõõøõõøöõøõõøõôúõöõõöõõöõõöõõöõõöõõöõõöõõöõõöõõ in flex content seems like this. but in java server side, the content is "77 22 34 0 0 0 ...". – Coenni Jun 02 '12 at 09:56
  • This statement "s = rst.getBytes(1);" would not able to read all bytes from database, you need to use stream to read all bytes i am adding extract in answer – Imran Jun 02 '12 at 10:04
  • But using that server function, I can show image in Java client application. Error is due to BlazeDS encoding-decoding I think. – Coenni Jun 05 '12 at 05:30