Skip navigation
Currently Being Moderated

Why won't the dyanamic text work here?

Feb 27, 2013 5:27 PM

I'll show pictures:


First Frame:





Second Frame here:



( the code: boxtwo = "Hello" + name + ". testing One TWOOOOOOOOOOetc.!!!!!" ; )




I put the name Carol in the dyanamic text yet it just called itself undefined.


Could you help please??

  • Currently Being Moderated
    Feb 27, 2013 6:34 PM   in reply to BingBingDing

    Your pictures didn't find their way here.  The code you show might only work in AS2, but using variables to define the text in a textfield is unreliable and should be avoided.


    Normally when you assign text to a textfield you assign it to the text property....


    boxtwo.text = "Hello" + name + ". testing One TWOOOOOOOOOOetc.!!!!!"



    If some text is not showing up you probably need to embed the font for your textfield(s)

    Mark as:
  • Currently Being Moderated
    Mar 2, 2013 8:51 AM   in reply to BingBingDing

    I think your problem may be that there is no text in the box in frame 1 when the frame script runs. Another possibility is that the variable is scoped only to frame 1.  I think AS1 used to act like that, but I'm not really a frame script person (it's bad practice!) so someone who is may be able to verify if it might work that was in AS3.  Or AS2. The fact that you're not assigning types to your variables and you're nor reporting any compiler warnings suggests you might be using AS2.

    Mark as:
  • Currently Being Moderated
    Mar 2, 2013 9:11 AM   in reply to BingBingDing

    In AS3, if you didn't use


    var name:String = boxone.text;


    you would see a compiler warning (assuming that you left strict mode on, which you should).


    However, in writing out that code for you, I see something that may be your problem.


    name is the instance name of the MovieClip. When you assign it in Frame 1, you're assigning it to a local variable that is used in preference to the larger instance variable. In frame 2, when you reference it, you're referencing the preexisting name of the MC, which you haven't assigned.  Although I'd expect that you would see something more like instance12345.


    Try using a variable name that doesn't conflict with an existing variable, like userName.

    Mark as:
  • Currently Being Moderated
    Mar 2, 2013 11:21 AM   in reply to BingBingDing

    You are assigning the value of the textfield to the variable before the textfield has any text in it.  The variable doesn't follow changes in the textfield, it is assigned whatever it is when the code executes.  You need to wait until the textfield has value before assigning it to anything.


    Try using an onChanged function assignment for the textfield....



    var name:String;


    boxone.onChanged = function(){

         name = boxone.text ;



    Also, you need to make sure that the layer that this code is on extends to any other frame where you intend to use the name variable.  This is likely why you get the undefined value.  If it only goes as far as the frame it is in, it is not available further down the timeline.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points