4 Replies Latest reply on Feb 15, 2007 5:54 AM by jeroencornelissen



      I have the following little demo code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
      import mx.controls.Button;
      import mx.core.UIComponent;

      public function init(): void
      var b:Button = new Button();
      b.label = "button";
      var u:UIComponent = new UIComponent();

      What I am trying to do here would seem very basic, but I just can't get it to work. What I was expecting is that the button would just show up because I added it to the UIComponent. But after I call addChild(u), nothing happens. Changing that line into addChild(b) works without a problem.

      The idea is to eventually add a Video object to the UIComponent, but since I can't even get a button to show up, I was hoping that anyone here could help me.

      Any help would be appreciated.

        • 1. Re: UIComponent
          FlightGuy Level 1
          UIComponent is not intended to be created and used as-is. It is the base class for a bunch of other classes, but doesn't actually draw anything. Also, it isn't a container and it won't pass on any of the calls to its children. Perhaps you could explain why you're adding the button to a uicomponent, rather than either adding it directly to the application, or putting it inside one of the Container classes (not Container itself, but Box, Canvas, etc).
          • 2. Re: UIComponent
            Chielosos Level 1
            What I'm looking to do is add a Video component to the stage. Since the Video component isn't derived from the UIComponent class itself, I need to add it to something else to have it show up on stage. My idea was to add the child (the Video object) to the UIComponent and then add the UIComponent to the stage (or some other container). But to keep things simple, I tried it out with a button. With the result mentioned :)

            If you have any more info, I'd love to hear it.
            • 3. Re: UIComponent
              peterent Level 2
              I believe the problem is that you never gave the Button, b, a size. You gave u a size (100x100), but not to b which would default to 0x0.
              • 4. Re: UIComponent
                jeroencornelissen Level 1

                I'm trying to add an image dynamically to the display list in Flex but it doesn't work.
                This is my AS code:


                package AS {

                import flash.display.Sprite;
                import flash.display.Loader;
                import flash.net.URLRequest;
                import flash.events.Event;
                import flash.display.Bitmap;
                import flash.display.BitmapData;
                import flash.geom.Matrix;
                import mx.core.*;

                public class BitmapLoader extends Sprite {

                private var _loader:Loader;

                public function BitmapLoader() {

                _loader = new Loader();
                _loader.load(new URLRequest("images/image.jpg"));
                _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);


                public function onComplete(event:Event):void {

                var bitmap:BitmapData = new BitmapData(_loader.width,_loader.height,false,0xFFFFFFFF);
                var mySprite:UIComponent = new UIComponent();

                bitmap.draw(_loader,new Matrix());

                mySprite.width = 91; mySprite.height = 91;
                mySprite.x = 50; mySprite.y = 50;

                mySprite.graphics.beginBitmapFill(bitmap, new Matrix());




                And here's my code in Flex's MXML:

                x="607" y="9"
                creationComplete="new BitmapLoader();">
                <![CDATA[ ... contact info ...]]>


                It just doesn't show the image... Any help?