Bitmap Asset from embedded resource to resource module with Flex 3

I really appreciate all the help I can solve on this issue that I have found.

I created several resource modules with the MXMLC tool using properties files.

The files are being generated correctly and I can load them using the resourceManager.loadResourceModule () function.

Now here's the problem.

In these files, I have added some images.

In the application, I make some changes to these images if they are BitmapAssets.

The problem is I get an error or null reference if I try the following.

// With this one I get null.
var image:BitmapAsset = resourceManager.getClass( 'myResourceBundle', 'mainImage' ) as BitmapAsset;

// With this one an error.
var image2:BitmapAsset = BitmapAsset( resourceManager.getClass( 'myResourceBundle', 'mainImage' ) );

      

Is there a way to do this and it works correctly?

Again, I really appreciate all the help I can get.

Thank.

+1


source to share


1 answer


resourceManager.getClass

returns a class, not an instance. Rewrite your code something like this:

var imageResource : Class = resourceManager.getClass('myResourceBundle', 'mainImage');

var image : BitmapAsset = new imageResource();

      



This should do the trick, although you may need BitmapAsset(new imageResource())

to if the compiler is complaining and can't remember how to do it right now.

+4


source







All Articles