3 Replies Latest reply on Aug 10, 2010 5:03 AM by rootsounds

    Generic custom control that can display an image or swf?

    ccay

      Hi,

       

      I want to create a custom control that can take an image or swf as an argument and display it in the same way.

       

      If the programmer uses this control (which essentially is a button with custom display) I want him to be able to just state the source and the text that is to be shown. Like this:

       

         <myControls:myButtonControl descriptionText="swf object" symbolObject="{Application.application.shape01swf}">

      or

         <myControls:myButtonControl descriptionText="img object" symbolObject="{Application.application.shape01img}">

       

      where shape01swf and shape01swf are embeded objects as follows:

       

         [Embed("../assets/swf/Shape01.swf")]
          public var shape01swf:Class;


         [Embed("../assets/images/Shape01img.jpg")]
         public var shape01img:Class;

       

      Which kind of object should I create in my custom control that can display this?

       

      Right now I have created a Class that extends VBox so that I can display the image/swf above the descriptionText.

      (I am using Flex 3.)

        • 1. Re: Generic custom control that can display an image or swf?
          BhaskerChari Level 4

          Hi CCAY,

           

          You can make use of VBox itself as your root tag and your component should look like...below..

           

          You can make use of the Image control to display both the image and also to load SWF as well....It will serve both purpose....just you set the source to it either a image or swf

           

          <mx:VBox>

               <mx:Image source="" />

               <mx:Text width="300" />

          </mx:VBox>

           

           

          Thanks,

          Bhasker Chari

          • 2. Re: Generic custom control that can display an image or swf?
            rootsounds Level 4

            Try taking a look at the SDK source to see what the controls in there such as Image do as well.

            1 person found this helpful
            • 3. Re: Generic custom control that can display an image or swf?
              ccay Level 1

              Aha, so the Image control can use an swf as a source as well?

              I just assumed that it could not and I would have to use the SWFLoader to do it.

               

              So, this is my solution:


                      override protected function createChildren():void{
                          iconField = new Image();
                          addChild(DisplayObject(iconField));
                         
                          textField = new Text();
                          addChild(DisplayObject(textField));
                         
                          super.createChildren();
                      }


                      private function init(e:Event):void{
                          iconField.source = symbolObject;
                          textField.text = descriptionText;
                      }

               

              Thanks!