views:

556

answers:

3

I'm trying to make a text effect where on every frame the textfield increases in size and decreases in opacity. I'm using the scaleX and scaleY properties of my dynamic textfield to enlarge, but it's doing so keeping the left registration point fixed. I want to make it scale up radially outward, or with the center point fixed. Can anyone tell me how to do this?

+1  A: 
 textfield.x -= textfield.width /2;
 textfield.y -= textfield.height /2;

if the x and y are 0 this will help

antpaw
I'd do `>> 1` instead of `/ 2` so you don't mess up the anti-aliasing by being on a fractional pixel. That said, since he's gonna scale it right after anyway, probably doesn't matter.
Cory Petosky
+1  A: 

You can easily create a wrapper for the TextField (i.e. a Sprite containing the TextField) to enforce the registration point to the middle. If the TextField is dynamic make sure it's autoSize is set to LEFT. Thereafter you can just set it's x/y position to -textField.width*.5/-textField.height*.5. Of course the scaling should be applied to the parent.

Theo.T
Putting it in a Sprite and setting the reg point to the middle was the easiest fix for me. Thanks to all for the great answers!
Mattk
A: 

I'm doing pretty much exactly that right now. I am using a wrapper a Theo.T mentions.

This is my code (most of it):

private function drawText(str:String, size:int = 16, px:int = 0, py:int = 0):void {
    var mc:MovieClip = new MovieClip();
    var tf:TextFormat = new TextFormat("Verdana", size, _textcolor);
    tf.align = "center";
    var _txt:TextField = new TextField();
    _txt.embedFonts = true;
    _txt.wordWrap = true;
    _txt.selectable = false;
    _txt.autoSize = TextFieldAutoSize.CENTER;
    _txt.antiAliasType = "advanced";
    _txt.defaultTextFormat = tf;
    _txt.width = _textwidth;
    _txt.text = str;
    _txt.x = -_txt.width / 2;
    mc.scaleX = mc.scaleY = _scalemin;
    mc.x = px;
    mc.y = py;
    mc.addChild(_txt);
    addChild(mc);
    startMove(mc);
}

private function moveText(e:Event):void {
    var mc:MovieClip = MovieClip(e.target);
    if (mc.scaleX >= _scalemax) {
        mc.scaleX = mc.scaleY = _scalemax;
    } else if (mc.y > _ymin) {
        mc.scaleX = mc.scaleY *= _scalegrow;
    }
    if (mc.alpha <= 0.1) {
        mc.removeEventListener(Event.ENTER_FRAME, moveText);
        mc.parent.removeChild(mc);
    }
}
mga