2 Replies Latest reply on Aug 21, 2009 7:54 AM by aaronb2

    How to convert CSS embedded resource backgroundImage into Bitmap?

    aaronb2

      I am trying to convert the embedded resource backgroundImage to an bitmap so I can load it in Papervision.  The problem I am having is how do I convert it to bitmap.  I have tried different combinations to no avail.  The code I am using is below.  A side issue, I also noticed when my CSS skin does not have a backgroundImage defined I am still getting an object of class mx.skins.halo.ApplicationBackground, why is that?

       

      Thanks,

       

      Aaron

       

      BTW, Here is the code

       

      var g:Graphics = backgroundSprite.graphics;

      var selector:CSSStyleDeclaration = StyleManager.getStyleDeclaration("Application");
      var imageClass:Class = null;

      var imageObject:Object = null;

      var image:DisplayObject = null;

      // is there an image to load?
      imageObject = selector.getStyle("backgroundImage");

      imageClass = Class(imageObject);

       

      // **** Here's the problem--

      // Error #1034: Type Coercion failed: cannot convert mx.skins.halo::ApplicationBackground$ to mx.skins.halo.ApplicationBackground.

      image = imageClass(imageObject) as DisplayObject;

      if (image) {

              var data:BitmapData = new BitmapData(image.width,image.height,true,0x000000);

              data.draw(image as IBitmapData);

              g.clear();
               g.beginBitmapFill(data,null,false);
               g.drawRect(0,0,viewport.width,viewport.height);   
              g.endFill();
          }