views:

404

answers:

2

I have loaded a SWF which is created in Flash CS9 (AS3). I'm having problem passing Bitmap (or BitmapData) from the flex app to the loaded SWF.

Invoking of other functions in the loaded from Flex works, but when I try to pass a Bitmap to the loaded SWF, nothing happens. Here's a sample code:

FLEX:

try{
    var bm:Bitmap = (someEvent.data as Bitmap);
    imageHolder.source = bm; // works fine with container inside flex app
    flashSWF.setPhotoBitmap(bm); 
}catch(e:Error){
    tracer("error = "+e);   
}

FLASH:

function setPhotoBitmap(b:Bitmap):void{
    addChild(b); // throws error
}

The above throws a TypeError: Error #2007 Probably because b is null.

Is there any restriction I should be aware of, or am I doing something wrong here?

Cheers!

A: 

When exactly are you calling setPhotoBitmap ?

I think you should be fine if you do it in the INIT handler of your SWFLoader instance. That is when your swf is loaded and all of it's classes initialized.

Goodluck!

George Profenza
A: 

I found a solution to this. The problem was because of a silly error I made.

var bm:Bitmap = (someEvent.data as Bitmap);

The problem was in the above line. 'someEvent' was generated by FileReference.load() and I did not realize that data is ByteArray and not a Bitmap.

All this time, I was passing byteArray to a function which accepts only bitmap.

Sorry folks, my bad!

Thanks for you time.

P

Yeti