here is a quick custom class that would do the trick:

class drawing.GreenRect extends MovieClip {

  private rect:MovieClip;
  private text1:TextField;
  private text2:TextField;
  public static var symbolName:String = "__Packages.drawing.GreenRect";
  private static var link = Object.registerClass(symbolName, GreenRect);

  public function GreenRect(parent:MovieClip):Void {}
    draw();
    Stage.addListener(this);
  }

  private function draw():Void {
    rect = createEmptyMovieClip("rectangle", 1);
    text1 = createTextField("text1", 2, 0, 0, 100, 20);
    text2 = createTextField("text2", 3, 0, 20, 100, 20);
  }

  private function onResize():Void {
    // do the resizing & positionning stuff here...
    this._x = ...
    this._y = ...
    rect._width = ...
    rect._height = ...
    text1._width = ...
    [...]
  }

}

Just instanticiate it like this:

var back:GreenRect = _root.attachMovie(GreenRect.symbolName, "myRect", someDepth);
back._x = ...
back._y = ...



Julien

Alexander Farber a écrit :
Hello!

I'd like to draw a green rectangle underneath 2 TextFields.

As my flash app. will have WIDTH=100% in the HTML-page,
I'd like to handle the eventual resizing of it. For that I've registered
an onResize-listener at the Stage (see the resize() function below).

While resizing works ok for the both TextFields (called area_txt
and field_txt), it fails for the green rectangle: the old rectangle
doesn't get erased. Does anybody please have an advice for me?
I don't see any Stage.clear() method in the help-docs...

I've prepared a complete test case below, please copy-paste it
and resize the movie window and you'll see the problem I have:

createEmptyMovieClip('back_mc', getNextHighestDepth());

createTextField('area_txt', getNextHighestDepth(), 5, 5, 5, 5);
with (area_txt) {
    border = true;
    multiline = true;
    textColor = 0xFFFFFF;
}

createTextField('field_txt', getNextHighestDepth(), 5, 5, 5, 5);
with (field_txt) {
    border = true;
    type = 'input';
    textColor = 0xFFFFFF;
}

resize();

Stage.scaleMode = 'noScale';
var resizeListener:Object = new Object();
resizeListener.onResize = resize;
Stage.addListener(resizeListener);

function resize() {
    trace("Stage size: " + Stage.width + " x " + Stage.height);
    var text_width:Number = 3 * Stage.width / 4;
    var text_left:Number  = 10;
// draw a rectangle with a cut-off corner with (back_mc) {
        _alpha = 50;
        moveTo(text_left + 8, 30);
        lineStyle(0, 0xFFFFFF, 100);
        beginFill(0x008000, 100);
        lineTo(text_left + text_width, 30);
        lineTo(text_left + text_width, 290);
        lineTo(text_left, 290);
        lineTo(text_left, 30 + 8);
        endFill();
    }
    with (area_txt) {
        _x = text_left;
        _y = 30;
        _width = text_width;
        _height = 240;
    }
    with (field_txt) {
        _x = text_left;
        _y = 270;
        _width = text_width;
        _height = 20;
    }
}

Also I wonder, if there is a way to encapsulate the rectangle
drawing code insided the back_mc MovieClip? Then I'd just
have to position it and to change its _width and _height and
wouldn't need to touch its drawing guts (i.e. OOP-encapsulation).

I've tried create a MovieClip symbol and to put this code
into its 1st frame, but that didn't work (nothing was drawn):

        _alpha = 50;
        moveTo(8, 0);
        lineStyle(0, 0xFFFFFF, 100);
        beginFill(0x008000, 100);
        lineTo(_width, 0);
        lineTo(_width, _height);
        lineTo(0, _height);
        lineTo(0, 8);
        endFill();

Thank you
Alex

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to