5 Replies Latest reply on Jun 17, 2009 7:45 AM by dzeikei

    Problem in embedding a png file for a button's skin

    webvalue Level 1

      I am trying to embed a png graphic as a skin for a button using actionscript class for a custom component. It has an error: "unable to resolve 'btn.png' for transcoding" - see method 1 code below. However, it works fine in method 2. Code are all shown belown. Can someone help regarding why this happens and how to make method 1 work?

       

      Got error in method 1:

       

      package net.abc.free
      {

       

          import mx.core.BitmapAsset;
                       
          public class myComp extends Canvas {
            
              [Embed(source="assets/btn.png")]
              [Bindable]
              public var clasBtn:Class;
             
          public function myComp() {
              super();  
          }
          }
      }

       

       

      Successful in method 2: 

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
          <mx:Script>
              <![CDATA[
                  import mx.core.BitmapAsset;
                 
                  [Embed(source="assets/btn.png")]
                  [Bindable]
              public var clasBtn:Class;
              ]]>
             
          </mx:Script>
          <mx:Panel id="mainPanel" width="400" height="300" backgroundAlpha="0">
              <mx:HBox width="100%" height="100%" horizontalAlign="center" horizontalGap="100">
                  <mx:Button id="myBtn" upSkin="{clasBtn}"/>           
              </mx:HBox>
          </mx:Panel>
      </mx:Application>