关于在 AS3 项目中嵌入资产(图像)

发布于 2024-12-04 18:59:09 字数 356 浏览 1 评论 0原文

我正在使用flex sdk 4.5.1和flash开发来编译我的AS3项目。我有一些小图像,大约 12KB,使用 Loader 类加载它们是愚蠢的,所以嵌入是更好的解决方案。

但是,当我的主类顶部的这一行未注释时,我得到空白 swf

[Embed(source = "../assets/gui/play1.png", mimeType = "image/png")]
private var PlayUpImg:Class;

(当我注释掉它时,编译后的 swf 就可以了)

可能是什么错误。为什么我得到的是空白 swf?

我正在 FlashDevelop 中从事纯 AS3 项目

I am using flex sdk 4.5.1 and flash develop to compile my AS3 project. I have small images, about 12KB which is silly to load them using Loader class, so embeding is better solution.

However when this line at the top of my Main class is uncomented i get blank swf

[Embed(source = "../assets/gui/play1.png", mimeType = "image/png")]
private var PlayUpImg:Class;

(when i comment it out, the compilated swf is ok)

What could be the error. Why do I get the blank swf?

I am working on pure AS3 project in FlashDevelop

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扎心 2024-12-11 18:59:09

您可以尝试使用“application/octet-stream”mimetype 将 png 图像嵌入为任意二进制数据。然后,您将使用 Loader 对象的 loadBytes() 方法来加载 png 图像的二进制数据。以下是一个示例:

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;

    [SWF(width="256", height="256", backgroundColor="#FF0000")]
    public class Main extends Sprite 
    {
        [Embed(source = "assets/ie9.png", mimeType = "application/octet-stream")]
        private var IE9:Class;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);

        }// end function

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            var loader:Loader = new Loader();
            loader.loadBytes(new IE9());
            addChild(loader);

        }// end function

    }// end class

}// end package

[更新]

我知道这个答案已被接受,但这里有一个额外的好处。

在此处输入图像描述

在此输入图像描述

You could try embing the png image as arbitrary binary data by using the "application/octet-stream" mimetype. Then you would use a Loader object's loadBytes() method to load the png image's binary data. The following is an example of this:

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;

    [SWF(width="256", height="256", backgroundColor="#FF0000")]
    public class Main extends Sprite 
    {
        [Embed(source = "assets/ie9.png", mimeType = "application/octet-stream")]
        private var IE9:Class;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);

        }// end function

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            var loader:Loader = new Loader();
            loader.loadBytes(new IE9());
            addChild(loader);

        }// end function

    }// end class

}// end package

[UPDATE]

I know this answer has already been accepted but here's an extra added bonus.

enter image description here

enter image description here

浮生面具三千个 2024-12-11 18:59:09

您需要将图像添加到显示列表中:

package
{

    import flash.display.Bitmap;
import flash.display.Sprite;

    public class Main extends Sprite{

        [Embed(source = "../assets/gui/play1.png", mimeType = "image/png")]
        private var PlayUpImg : Class;

        public function Main()
        {
            var myImage : Bitmap = new PlayUpImg();
            addChild( myImage );
        }

    }

}

You need to add the image to the Displaylist:

package
{

    import flash.display.Bitmap;
import flash.display.Sprite;

    public class Main extends Sprite{

        [Embed(source = "../assets/gui/play1.png", mimeType = "image/png")]
        private var PlayUpImg : Class;

        public function Main()
        {
            var myImage : Bitmap = new PlayUpImg();
            addChild( myImage );
        }

    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文