I was trying to do a smooth animation sequence like this:
- Tween TextField alpha to 0.
- Tween background MovieClip to height 0.
- Change the text.
- Tween the background MovieClip to height of the changed TextField.
- Tween TextField alpha back to 1.
Unfortunately, when creating the timeline sequence the height of the TextField got “cached” and was not updated on runtime after the text of the TextField had changed. My workaround on this is to append to the timeline after the text has been changed, and not build the whole sequence at once.
Not sure how this would work if there had to be things done after updating the texts, but I assume you can insert at a specific time/label in the Timeline, so that would solve it, I assume.
Textbox SWF
Hm, not in the swf but I added code to remove the tweens once they are done, otherwise it keeps appending to the end of the timeline each time the animation is run.
Code:
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;
button_mc.addEventListener(MouseEvent.CLICK, update);
reset_mc.addEventListener(MouseEvent.CLICK, reset);
button_mc.buttonMode = true;
reset_mc.buttonMode = true;
popup_mc.x = 0;
popup_mc.y = 50;
popup_mc.body_txt.autoSize = TextFieldAutoSize.LEFT;
var texts:Array = new Array();
texts.push("Cotton candy sweet roll carrot cake candy. Jelly tart tart icing wafer carrot cake biscuit macaroon. Sweet roll pie faworki marshmallow bonbon bear claw. Chocolate caramels cake sweet roll marzipan. Lemon drops icing wafer soufflé brownie brownie candy canes donut. Muffin pastry gummies sweet roll dragée caramels jelly apple pie. Carrot cake fruitcake marzipan fruitcake dragée biscuit tootsie roll cookie. Marshmallow bonbon oat cake. Pudding cake gummies bonbon dessert caramels sugar plum candy bonbon. Wafer candy canes tiramisu brownie jelly-o. Liquorice pastry pie. Toffee dessert pie. Chocolate cake biscuit lemon drops gummies jelly-o cake cake candy canes sesame snaps.");
texts.push("Jelly beans macaroon brownie dragée. Jelly chocolate cake chupa chups caramels pastry sweet roll marshmallow. Liquorice gummies sweet roll. Tart liquorice chocolate faworki cake cake. Icing pastry marzipan jelly-o bear claw cookie ice cream lemon drops. Jelly-o bear claw tart applicake. Ice cream pie sweet tootsie roll gummi bears dessert cotton candy. Bonbon bear claw bonbon pudding. Gummies jelly-o liquorice candy canes sweet roll. Bonbon apple pie marzipan pastry jelly beans marzipan chocolate bar powder. Cake biscuit candy lemon drops marshmallow chocolate cake applicake. Jelly beans croissant pie applicake apple pie sugar plum lollipop.");
texts.push("Tootsie roll croissant liquorice. Dragée chocolate cake macaroon. Chocolate bar gummi bears ice cream faworki wypas. Bonbon bear claw candy cotton candy gummies dessert. Sesame snaps cotton candy marshmallow soufflé jujubes gingerbread pie pudding. Topping icing tiramisu pie bonbon halvah. Fruitcake wypas tootsie roll wafer icing. Brownie topping sweet roll carrot cake faworki chocolate bar gummies cookie chocolate. Bear claw pudding muffin candy canes. Fruitcake croissant chocolate apple pie donut brownie cotton candy jelly sweet roll. Carrot cake lemon drops caramels icing muffin halvah. Croissant biscuit muffin marshmallow. Candy jelly-o candy canes sweet roll caramels wypas gingerbread danish.");
var tm:TimelineMax = new TimelineMax({onComplete: removeOldTweens});
tm.stop();
tm.appendMultiple([new TweenLite(popup_mc.header_txt, 1, {alpha: 0}), new TweenLite(popup_mc.body_txt, 1, {alpha: 0})]);
tm.appendMultiple([new TweenLite(popup_mc.greenBody_mc, 1, {height: 0}), new TweenLite(popup_mc.greenArrow_mc, 1, {y: popup_mc.greenHeader_mc.y + 25})]);
tm.append(new TweenLite(popup_mc, 1, {x: 50}));
tm.addCallback(changeText, 3);
var headerTween:TweenLite;
var bodyBgTween:TweenLite;
var arrowTween:TweenLite;
var textFieldTween:TweenLite;
function changeText():void {
popup_mc.header_txt.text = "Another headline on this information box";
popup_mc.body_txt.text = texts[int(Math.random() * 2)];
popup_mc.body_txt.width = 290;
// append to timeline
headerTween = new TweenLite(popup_mc.header_txt, 1, {alpha: 1});
bodyBgTween = new TweenLite(popup_mc.greenBody_mc, 1, {height: popup_mc.body_txt.height+10});
arrowTween = new TweenLite(popup_mc.greenArrow_mc, 1, {y: popup_mc.body_txt.height+10+25});
textFieldTween = new TweenLite(popup_mc.body_txt, 1, {alpha: 1});
tm.append(headerTween);
tm.appendMultiple([bodyBgTween, arrowTween]);
tm.append(textFieldTween);
}
function removeOldTweens():void {
tm.remove(headerTween);
tm.remove(bodyBgTween);
tm.remove(arrowTween);
tm.remove(textFieldTween);
headerTween = null;
bodyBgTween = null;
arrowTween = null;
textFieldTween = null;
}
function update(e:MouseEvent):void {
tm.play();
}
function reset(e:MouseEvent):void {
popup_mc.x = 0;
popup_mc.y = 50;
popup_mc.header_txt.text = "Header text!";
popup_mc.body_txt.text = "Blah blah";
tm.gotoAndStop(0);
}