views:

66

answers:

1

Anybody that happens to know how to do this would really be helping me out.

Maybe its simple, I don't know, but it involves embedded SWF's so I imagine it could entail interacting with event handlers or methods in an embedded SWF.

But anyway, here it is:

I have several embedded SWF's on a canvas (in SWFLoaders) and when one of them changes visually I need to know which one changed.

The 'render' event provides only part of the solution:

If an SWFLoader contains a videodisplay there are continual render events generated in the parent app while that videodisplay is running. If the SWFLoader just contains some static input control otoh, there are no render messages in the parent app until someone interacts with that control and changes it visually, and then there are render events broadcast in the parent app. So, this is clearly part of what my requirements are.

The problem with the render event however, is that it does not tell you which embedded SWF actually changed (in the target or currentTarget.)

But I need to know which one changed.

(Are there seperate render messages being generated within an embedded app (seperate from those in the parent app) for example, that could be detected.)

+1  A: 

My solution is as follows:

When a render event occurs, I check if there is a visible swfloader within the browser window, and then I do a BitmapData.draw of its contents to a bitmapdata which is saved. With each new render event, I compare 10% of the pixels of the saved bitmap to the new bitmap and that will tell me whether or not the embedded .swf visual content has actually changed. a 10% sample has proven to be more than sufficient (just iterating through the vectors of the respective bitmaps with the vector index incrementing by 10, instead of 1.)


BitmapData.draw is plenty fast and iterating through 10000 vector elements is like a millisecond.

Mark
This is probably the best answer.
Jasconius
Well, its interesing you would say it was "the best". I was thinking it was "good enough" and of the saying, "The best is enemy of the good enough." I had tunnel vision for a couple of days unfortunately about how I wanted to do this so was unable to see other solutions.
Mark
It might be faster to draw the second bitmapdata over the first one with a difference blend mode, then do a getColorBounds to see if any pixels are not black.
sharvey
It sounds like it would be faster. I'll check into that and get back to you. Incidentally, I found that for some controls the BitmapData.draw method is quite a bit slower than the norm, for example a RichTextEditor example in the flex-sdk is much slower than for any of the other example controls. My point being - to return to my original post - I really do need something in the flash player to tell me if an embedded SWF has changed visually.
Mark
It sounds like it would be faster. I'll check into that and get back to you. Incidentally, I found that for some controls the BitmapData.draw method is quite a bit slower than the norm, for example a RichTextEditor example in the flex-sdk is much slower than for any of the other example controls. My point being - to return to my original post - I really do need something in the flash player to tell me if an embedded SWF has changed visually.
Mark
sharvey, its not doing what I expected:var bmd_s2:BitmapData = bmd_s.clone();bmd_s2.draw(bmd_img[n],null,null,"difference"); Dumper.info( bmd_s2.getColorBoundsRect(0xFFFFFFFF,0,false).toString()); if (!bmd_img[n].compare(bmd_s)) { Dumper.info("the same"); return;} Here's the ouput[INFO]: (x=77, y=34, w=289, h=147) (String)[INFO]: the same (String)so they're the same but GetColorBoundsRect is returning a large rectangle. (Probably missing something.)(BTW BitmapData.compare is not all that fast -that's why I'm not using it.)
Mark
testing............
Mark