UI Component: two classes--one draws the other doesn't (Flex/AS)

I am working with a flex project with a main mxml file and two actionscript classes that draw graphics. From reading tons of articles and posts I discovered that they must extend UIComponent, which they do. The first actionscript class draws the image fine. The first class then makes the call to create a new object. The second object does not display. In the pure actionscript version I had to pass the stage as a reference for the second class to draw.

I also found a similar question here at stackoverflow: UIComponent extended class isn't showing UIComponent extended class. But I was not sure how to apply it to my example.

Which, if any UIComponent methods should be overrided for the second object to display? How specifically should I implement them in this example?

If there is a better or simpler answer to this problem, that is also appreciated. This is a simplified example of a problem I'm having with a more complex project.

// First class "Ball" draws a circle successfully then creates a second object "MyRect" 

        package dr {
        import flash.display.*;
        import flash.display.Sprite;

        import mx.core.*;

        public class Ball extends UIComponent {
            public function Ball()
                var vCircle:Sprite = new Sprite();
                vCircle.graphics.drawCircle(100, 150, 40);

                var rect:MyRect = new MyRect();

    // Second class "MyRect" (does not display)

    package dr {
    import flash.display.*;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.geom.*;

    import mx.core.*;

    public class MyRect extends UIComponent
        public function MyRect()

            var vRect:Sprite = new Sprite();
            vRect.graphics.beginFill(0x0000ff, 1);
            vRect.graphics.drawRect(300, 150, 150, 75);

            //var ui:UIComponent = new UIComponent();


    //Here is the MXML main file:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   minWidth="955" minHeight="600">
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        <mx:Panel id="myPanel" width="700" height="600" paddingLeft="10" paddingTop="10">   


In your Ball class, you instantiate a new MyRect class; however, you don't add it to the stage:

var rect:MyRect = new MyRect();

Need Your Help

Creating an SQL query from a dictionary

python mysql sql dictionary

I have a function to update an entry in a database (MySQL) and it needs to be as dynamic as possible.

One liner to re-size two matrices to the same size as the smaller matrix

matlab resize

Say i have two matrices: A and B and they are two different sizes. For eg:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.