简体   繁体   English

通过SWFBridge将BitmapData对象从AS2 SWF传输到父AS3 SWF

[英]Transfer a BitmapData object from an AS2 swf to a parent AS3 swf via SWFBridge

I need to transfer a BitmapData object created in an AS2 swf to an AS3 swf. 我需要将在AS2 SWF中创建的BitmapData对象传输到AS3 SWF。 I'm using gskinner's SWFBridge to establish a two way communication between both flash movies. 我正在使用gskinner的SWFBridge在两个Flash电影之间建立双向通信。

The AS3 movie loads the AS2 swf which works completely standalone and lets the user manipulate MovieClips and finally generate an image from the composition he creates. AS3影片加载AS2 SWF,该SWF完全独立运行,并允许用户操纵MovieClips并最终根据他创建的构图生成图像。 I need the AS3 movie to receive this image (bitmapData), do some fancy image processing stuff AS2 isn't able to do and send the new image back to the AS2 movie. 我需要AS3电影来接收此图像(bitmapData),做一些精美的图像处理工作,AS2无法做,然后将新图像发送回AS2电影。

So here's the code 所以这是代码

AS2 swf: AS2 SWF:

var userCompo_mc:MovieClip = container.createEmptyMovieClip("userCompo_mc",10);
var image:BitmapData = new BitmapData(userCompo_mc._width, userCompo_mc._height);
finalCompo.attachBitmap(image); // Just to make sure the final bitmap is right
image.draw(userCompo_mc, compo.title);

//Send the image to the AS3 movie
sb1.send("imageTransfer",image);

AS3 swf: AS3 SWF:

function imageTransfer(bitmapData:BitmapData, title:String):void
{
    var bmp:Bitmap = new Bitmap(bitmapData);
    this.addChild(bmp);
    trace(title); // --> returns the right title
    trace(bitmapData); // --> returns null
}

I think using something like copyPixel32(), saving everything into an array and then passing it to AS3 would do the trick but it's really a performance hog. 我认为使用诸如copyPixel32()之类的东西,将所有内容保存到一个数组中,然后将其传递给AS3可以解决问题,但这确实是一项性能损失。

Also, I'm not allowed to convert the AS2 swf into AS3 code. 另外,我不允许将AS2 SWF转换为AS3代码。

Any suggestions? 有什么建议么?

Thanks you! 谢谢!

It seems like the as2 movie adds some decorations/movieclips to a an image. 好像as2电影向图像添加了一些装饰/电影。 After that you draw it and send attempt to send it to as3. 之后,您绘制它并发送尝试将其发送到as3。

Since looping though all the pixels is slow, as you mention, I imagine it's faster to draw the as2 content from the as3 movie. 正如您提到的那样,尽管循环遍历所有像素都很慢,但我想从as3电影中绘制as2内容会更快。

eg 例如

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
loader.load(new URLRequest('yourAS2Movie.swf'),new LoaderContext(true));

function loaded(event:Event):void{
    var as2Clip:AVM1Movie = AVM1Movie(loader.content);
    var bd:BitmapData = new BitmapData(as2Clip.width,as2Clip.height,false,0);
    bd.draw(as2Clip);
    addChild(new Bitmap(bd));
}

In this snippet the as2 content is drawn on load. 在此代码段中,as2内容是在加载时绘制的。 In your case you would trigger/call a function that draws the as2 content via SWFBridge, after the as2 movie is ready/setup for what you need. 在您的情况下,您会触发/调用一个函数,以便在准备/设置了所需的as2电影之后,通过SWFBridge绘制as2内容。

This works assuming you want to display the as2 content inside the as3 movie, which means you will load the as2 movie anyway. 假设您要在as3电影中显示as2内容,则此方法有效,这意味着您仍将加载as2电影。 If not, either you load the as2 content, but don't add it to the display list, which means you'll be loading the as2 movie. 如果不是,则加载as2内容,但不要将其添加到显示列表中,这意味着将要加载as2电影。 Otherwise, you could try to save your final bitmap from the as2 movie using a server side language(like php for example), then trigger a function in the as3 movie, via SWFBridge, that will load the previously saved image. 否则,您可以尝试使用服务器端语言(例如php)从as2电影中保存最终位图,然后通过SWFBridge在as3电影中触发一个函数,该函数将加载先前保存的图像。

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM