views:

586

answers:

2

In Flex3, I could compile pure as3 code and use "embed" tags to load in images. This was done by Flex making a BitmapAsset class.

I can still do this in Flex4.

However, there was a trick to fakeout flex3 and use my own mx.core.BitmapAsset class to remove some of the extraneous stuff Flex's BitmapAsset brings in with it. This is described here: http://www.ultrashock.com/forums/flex/embed-flex-assets-without-using-flex-123405.html

Unfortunately, I cannot get these tricks to work with Flex4 and get smaller file sizes. I end up with the error "VerifyError: Error #1014: Class mx.core::BitmapAsset could not be found."

This error leads me to this forum, and a solution as described there: http://tech.groups.yahoo.com/group/flexcoders/message/148762

Following this advice, I add -static-link-runtime-shared-libraries=true, and my swf loads without an error... but this means I am loading in the pieces of the flex framework I wanted to omit (and the file size says so too).

Is there a better way to fake out flex4 when it comes to using Embed?

+1  A: 

Will something like work ?

[Embed(source="yourImage.jpg")]
private var ImageC:Class;
private var image = new ImageC();

Keith Peters has a nice article on the subject.

George Profenza
also, is it an actionscript or a flex project? Maybe for flex projects it defaults to using BitmapAsset
George Profenza
Yes, that is the technique for embedding assets when compiling as3 projects using the command line tools provided with flex. Assets embedded this way require some classes from the flex framework. This first link in my post reveals a technique to trim down the size of those classes, resulting in smaller file swf files. Embedding assets with flex4 has resulted in slightly larger swf files and the old technique from the first link no longer works.
jedierikb
@jdierkb I wonder if Joa Ebert's Reducer works on flex4 generated swfs(http://blog.joa-ebert.com/2009/08/08/reducer/). Should be something like java -jar reducer.jar -input old.swf -output new.swf from Terminal/Command Prompt. You will need java 1.6, so you should be fine on the PC, but on osx you will need the java update from apple and it might be handy to export the path in ~/.bash_profile (export PATH=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands:$PATH). If this works, it would be a solution for the filesize, but not for the mx.* issue.
George Profenza
A: 

I've created a test project in Flex 4 with [Embed] and fake BitmapAsset.as and can't see the exception:

package
{
import flash.display.Sprite;
public class EmbedTest extends Sprite
{
    public function EmbedTest()
    {
        addChild(new smile());
    }

    [Embed("smile.png")]
    private var smile:Class;
}
}

Try to add -link-report link-report.xml compiler option and check link-report.xml file in bin-debug.

Do you have BitmapAsset.as there? If no, you may have excluded it by externs, external-library-path or load-externs.

Maxim Kachurovskiy