0
votes

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

2

2 Answers

6
votes

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

1
votes

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 );
        }

    }

}