A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: TextField problem and centering tween problem

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    69

    TextField problem and centering tween problem

    The final idea is: there are multiple movieclips on stage, on keypress, mc1 will scale larger (tween), text will fade in on corner of stage (tween), audio associated with that mc will play ... then text will fade out and mc1 will scale back down to original size.

    The problem (highlighted line where I think problem is in code):

    1. When I scale the mc, it should end up at center of the stage from it's original location. Right now, it goes off stage first (off top left), THEN scales to center.

    2. I'm formatting text in an array first, then trying to have it show up at the same time as the tween function occurs. The formatting works, but it doesn't show up at all when I say "addChild(textField);" at the time the function runs. Ultimately, I have to set this inside a tween to fade in and out, but for now, I'd at least like to make it show up on stage.

    Any thoughts?

    Code:

    var animalNames:String = "Horse, Cow , Sheep";
    var animals:Array = animalNames.split(", ");
    var total:int = animals.length;
    var textField:TextField = new TextField();
    var format:TextFormat = new TextFormat();

    stage.addEventListener(KeyboardEvent.KEY_DOWN, tweenHorse);

    for (var i:int = 0; i < total; i++){
    textField.defaultTextFormat = format
    format.font = "Verdana";
    format.color =0x000000
    format.size = 24;
    format.bold = true;
    textField.autoSize = TextFieldAutoSize.LEFT;
    textField.background = true;
    textField.backgroundColor = 0xFFFFFF;
    textField.text = animals[i]
    textField.x = 50*i
    //addChild(textField); (this works here)
    trace(animals[i]);

    }

    function tweenHorse():void
    {
    setChildIndex(h1_mc, 2);
    var tweenHorseX:Tween = new Tween(h1_mc,"scaleX", Strong.easeOut,1,3,secs,true);
    var tweenHorseY:Tween = new Tween(h1_mc,"scaleY", Strong.easeOut,1,3,secs,true);
    var tweenCenterX:Tween = new Tween(h1_mc, "x", Strong.easeOut, 1, stage.stageWidth/2, secs, true);
    var tweenCenterY:Tween = new Tween(h1_mc, "y", Strong.easeOut, 1, stage.stageHeight/2, secs, true);


    addChild(animals[0]); //but this does NOT work here
    trace("hello horse");
    }
    I also tried
    "addChild(textField);"
    "addChild(textField[0]);"
    "addChild(animals.textField[0]);"
    and a few other things that didn't work and probably don't make sense - but I tried LOL.
    Last edited by Leftyplayer; 09-25-2009 at 12:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center