Drawing (Graphics) Confusion

In brief: I had a MovieClip, drew on it (its only content) and it refused to show up. I then instanciated a blank MovieClip in the library tied to this class, and it still refused to show up. I then scribbled on it and everything worked fine. I then erased the scribbles and everything still worked fine. I then deleted the associated library item and everything continued to work fine, like it should have done in the first place. What happen?

So here are the details:

In my code, I had three MovieClips in my library that each descended from class Foo, which had no associated Library item at all. They were originally more complicated, but as time went on, I found other ways to work with them and they were reduced to plain rectangles (FooRed, FooBlue, FooGreen) with a specific texture drawn dynamically on top. I figured “that’s just silly” so I replaced the calls to instantiate FooRed, etc, with calls to create Foo itself, which would be created dynamically and not be from the library at all. I would assign a colour to each Foo object at construction and then tell Foo to draw the rectangles its own darn self. But once I ran the code, I found that the Foo objects appeared empty… or at worst, not at all (invisible is invisible). Both the base rectangle and texture were gone.

Here’s some pertinent code.


public function Foo(c:uint, bitmap:BitmapData) {
            // New code.
            base = new Sprite();
            addChild(base);
            baseColor = c;
            // End new code
            
            texture = new Sprite();
            addChild(cbTexture);
            texture.visible = false;

            draw(bitmap);
}

// Draw, which is sometimes called externally to change the texture.  The color never 
// changes.
public function draw(bitmap:BitmapData):void {
            // New code.
            base.graphics.clear();
            base.graphics.beginFill(color);
            base.graphics.drawRect(0, 0, width, height);
            base.graphics.endFill();
            // End new code.

            texture.graphics.clear();
            texture.graphics.beginBitmapFill(bitmap);
            texture.graphics.drawRect(0, 0, width, height);
            texture.graphics.endFill();
}

After some testing in myriad directions (mostly in other classes, like doodling in the containing MovieClip, but drawing onto the clip itself, even from another class, failed to work), I went to the library and created an object directly tied to Foo. Nothing. I scribble on it with yellow pencil, however, and suddenly everything’s back in place! It continued to work fine even when I removed the scribbles and, subsequently, the library item. The code and flash file were back to where they had been at the start, except now it was, you know, working.

Ever feel like Flash has been flipping you off for an hour? Seriously, if anyone has an explanation, I’d love to hear it.