1 Reply Latest reply on Dec 22, 2009 8:58 PM by ShardulSingh

    Image inside a UIComponent

    Flex_

      How can I display an image inside a UIComponent (or a Sprite for that matter)?

      I have a custom UI Component .. I am adding an Image and textField to this component. When I add this component to the Canvas .. thje Image is not displayed.

       

      Please help me to resolve this issue. Thanks in advance.

        • 1. Re: Image inside a UIComponent
          ShardulSingh Level 3

          Hi,

           

          For image inside the sprite find the link below.
          http://shardulbartwal.wordpress.com/2009/09/18/using-image-inside-the-sprite-in-flex/

           

          And for image inside the UIcomponent find the code below.

           

          MainApplication.mxml

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              layout="absolute" creationComplete="onCreationComplete()">
          <mx:Script>
              <![CDATA[
                  import mx.core.UIComponent;
                  import mx.controls.Image;
                  private function onCreationComplete():void
                  {
                      var uiComp : UIComponent = new UIComponent();
                     
                      uiComp.width = 400;
                      uiComp.height = 400;
                     
                      var img : Image = new Image();
                      img.source = "rose1.jpg";
                      img.width  = 300;
                      img.height = 300;
                      uiComp.addChild(img as DisplayObject);
                     
                      can.rawChildren.addChild(uiComp);
                  }
              ]]>
          </mx:Script>
              <mx:Canvas id="can" width="500" height="500"/>
          </mx:Application>

           

           

           

          with Regards,

           

          Shardul Singh Bartwal