为什么装载机对象杀死的BitmapData的draw();? [英] Why do Loader objects kill bitmapdata draw();?

查看:203
本文介绍了为什么装载机对象杀死的BitmapData的draw();?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的code是一个简单的添加和保存程序。您preSS Add按钮将内容添加到画布上,比preSS的exportButton在其当前状态保存在画布上的图像到您的桌面。这code正常工作时,我加入圈子对象被绘制在画布上的油画。问题在于,当我尝试加载巴纽到画布上。一旦加载的内容被添加到画布的exportButton停止工作一起,不再响应。是什么原因造成加载的内容突破code?

The code below is a simple add and save program. You press the addButton to add content to the canvas and than press the exportButton to save an image of the canvas in its current state to your desktop. This code works fine when I add circle objects to the canvas that are drawn to the canvas. The problem lies when I try to load a .png into the canvas. Once the loaded content is added to the canvas the exportButton stops working all together and no longer responds. What is causing the loaded content to break the code?

的**这种POST HASS编辑完毕二零一二年三月三十零日下面列出的是工作code *

**This POST HASS BEEN EDITED AS OF MARCH 30, 2012 LISTED BELOW IS THE WORKING CODE*

public class Application extends MovieClip
{
    public var canvas:MovieClip = new MovieClip();
    public var addBtn:MovieClip = new MovieClip();
    public var exportBtn:MovieClip = new MovieClip();
    public var _content:BitmapData;

    public function Application()
    {
        canvas.graphics.beginFill(0x333333);
        canvas.graphics.drawRect(0,0,450,450);
        canvas.graphics.endFill();
        addChild(canvas);

        addBtn.graphics.beginFill(0x999999);
        addBtn.graphics.drawRect(0,0,50,50);
        addBtn.graphics.endFill();

        exportBtn.graphics.beginFill(0x999999);
        exportBtn.graphics.drawRect(0,0,50,50);
        exportBtn.graphics.endFill();

        canvas.x = stage.stageWidth / 2 - canvas.width;
        addBtn.x = exportBtn.x = canvas.x +(canvas.width +25);
        exportBtn.y = addBtn.height + 25;

        addBtn.addEventListener(MouseEvent.CLICK, addClick);
        exportBtn.addEventListener(MouseEvent.CLICK, exportClick);

        addChild(canvas);
        addChild(addBtn);
        addChild(exportBtn);
    }
    private function addClick(event:MouseEvent):void
    {
        var loader:Loader = new Loader();
        loader.load(new URLRequest("alphabet/a.png"));
        loader.x = Math.random() * canvas.width;
        loader.y = Math.random() * canvas.height;
        canvas.addChild(loader);
    }
    private function exportClick(event:MouseEvent):void
    {
        _content = new BitmapData(canvas.width,canvas.height);
        _content.draw(canvas);
        saveBitmap();
    }
    private function saveBitmap():void
    {
        var encodedContent:ByteArray = PNGEncoder.encode(_content);
        var fileWindow:FileReference = new FileReference();
        fileWindow.save(encodedContent, "Image_randomly.png");
    }
}

}

推荐答案

该问题可能是跨域安全问题。如果你是从一个网站不是您自己装,检查,以确保它在domain.com/crossdomain.xml一个跨域策略。还可以设置<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load%28%29"相对=nofollow>的LoaderContext (负载的第二个参数)。事情是这样的: loader.load(http://www.example.com/myimage.jpg,新的LoaderContext(真)); 否则,您可以加载图像其他网站,但不能访问实际的位图数据,其中平局()要求。

The problem may be crossdomain security issues. If you are loading from a site other than your own, check to make sure it has a crossdomain policy at domain.com/crossdomain.xml. Also set the LoaderContext (the second argument of load). Something like this: loader.load("http://www.example.com/myimage.jpg", new LoaderContext(true)); Otherwise, you can load images from other sites but not access the actual bitmapData, which a draw() requires.

此外,你应该至少有一个浏览器安装调试播放器,并运行它,并看看是否有任何错误。

Also, you should install a debug player on at least one browser and run it there and see if there are any errors.

这篇关于为什么装载机对象杀死的BitmapData的draw();?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆