0
votes

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!

2
What type is imageHolder? Where is it defined? - Lior Cohen
What other functions are you invoking on the loaded SWF? How are you loading this SWF? You need to provide more details on the flow of events here. - Lior Cohen
Hi Lior, here are some details: 1) imageHolder is Flex's SWFLoader. It is a visual UI in Flex's stage. 2) I'm loading the Flash swf using another SWFLoader in Flex. like this: <mx:SWFLoader id="flashSwfLoader"/> 3) Once SWF is loaded I'm doing this: flashSWF = flashSwfLoader.content as MovieClip; 4) Then I'm successfully calling many functions using flashSWF(in the swf's timeline) 5) The problem arose only when Bitmap was passed to one of it's function. Hope those details gives a clearer picture. Thanks! - Yeti
I need some code showing the events you're using to start interacting with the loaded SWF. For example: an event handler for the APPLICATION_COMPLETE event fired by the loaded SWF. Also, can you be more specific about the functions you are calling in the loaded SWF? Are these built-in functions or your own functions (e.g. MyFunc() VS addChild(), etc). - Lior Cohen

2 Answers

0
votes

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!

0
votes

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