zakdances
zakdances

Reputation: 23735

Why can't I make a visible movieclip?

I'm trying to make just a simple square movieclip show up on my stage, and it seems like nothing I've tried works...nothing appears on the stage! My code:

       var mc:MovieClip = new MovieClip();
        mc.x = 0;
        mc.y = 0;
        mc.width = 200;
        mc.height = 200;
        mc.opaqueBackground = 0xCCCCCC;

        // new ColorTransform object
        var obj_color:ColorTransform = new ColorTransform();
        // setting the new color we want (in this case, blue)
        obj_color.color = 0x0000ff;
        // applying the transform to our movieclip (this will affect the whole object including strokes)
        mc.transform.colorTransform = obj_color;

        this.stage.addChild(mc);
        mc.x = 0;
        mc.y = 0;

Why isn't my movieclip appearing on the stage?

Upvotes: 0

Views: 103

Answers (1)

Mike Welsh
Mike Welsh

Reputation: 1559

Your MovieClip contains nothing, so nothing is displayed. You are trying to cause the MovieClip to display a gray box by setting width and height and opaqueBackground, but unfortunately this doesn't work. width and height will only resize a clip that already has some content. If width and height are 0, then changing them has no effect, because trying to scale 0 results in 0. You can notice this by doing trace(width) after you set it to 200.

If you want to display a rectangle, use the drawing API to draw it in the clip:

var mc:MovieClip = new MovieClip();
mc.x = 0;
mc.y = 0;
mc.graphics.beginFill(0xCCCCCC);
mc.graphics.drawRect(0, 0, 200, 200);
mc.graphics.endFill();
addChild(mc);

Upvotes: 4

Related Questions