11 Replies Latest reply on Jun 17, 2007 11:32 AM by Greg Dove

    Displaying Var With Other Text

    ZypheR2007 Level 1
      Is it possible to display a users entered name throughout paragraphs of writing and make the paragraphs look natural no matter how short or long the name is?

      Maybe the summary was enough to make you figure it out but I'll explain. I have a paragraph which I would like to begin with my users name. Later on in the flash I would like to be able to have the users name appear in different parts of paragraphs.

      At the moment I have the dynamic text box at the start of a static text box. The problem is when a users name is very short it leaves spaces to the left as my text is position to the right.

      This works OK for starting the paragraph but not ideal when I want to use the name in the centre of para as it will leave large spaces either side of the players entered name unless the name is long enough to fill the space.

      Is there away to make the whole paragraph dynamic with a variable included among it?
        • 1. Re: Displaying Var With Other Text
          Greg Dove Level 4
          Just use one dynamic text box.
          Use one dynamic text box and just concatenate (add together) all the string elements to form your paragraph. If myTextField is the name of your dynamic text box...then:

          myTextField.text = "Greetings " + userName +" , I hope you're enjoying to read this simple acknowledgement of the fact that I know stuff about you. Your age is "+age+" and your social security number is "+socsecnum+ ". ";

          will create paragraph with your variables inside.
          • 2. Re: Displaying Var With Other Text
            ZypheR2007 Level 1
            Thanks for that I thought it would be something like that however I cannot get this to work.

            The "my" in myTextField is just part of name its not a required because I named my own Q1.text however I did try myQ1.text and I shortened the para to Q1.text = " + playername +" , I hope you're enjoying to read";

            When testing, the paragraph is displayed with Q1.text or myQ1.text aswel as the name of the var and not what the playersname var is holding. I've tried what I can with this.

            Any ideas what could be causing it?
            • 3. Re: Displaying Var With Other Text
              Greg Dove Level 4
              myTextField was not meant to be interpreted literally for your case. It was an example only.

              In the property panel for your dynamic textfield, name it Q1 (no spaces, periods or anything else)

              then you can set its text value with Q1.text

              Q1.text = playername +" , I hope you're enjoying to read";

              Assuming playername has a defined value that will work.

              If you're using as1/as2 and you have a variable assigned to the text field in the property panel.. well I recommend not to - avoid it if you can.


              • 4. Re: Displaying Var With Other Text
                ZypheR2007 Level 1
                Still not working, no var in my properties for the text box, text box is dynamic, I copied and pasted your code into it and it only shows the text exactly as you have written!

                This should probably be straight forward huh :-)
                • 5. Re: Displaying Var With Other Text
                  Greg Dove Level 4
                  Are you pasting the code inside the text field? That's the only thing I can imagine that you are doing. Don't do that if you are. It should go as code in the frame. And you will need a playername variable that is defined and has a value at the time the code to display the text is run.

                  And if that's what you're doing then you will need to start by learning from some tutorials on the web and/or read the adobe livedocs to get some more general understanding of how things work with actionscript.
                  • 6. Re: Displaying Var With Other Text
                    ZypheR2007 Level 1
                    ha ha no I thought it went in the Actions Frame however that displayed nothing at all so I changed it back to putting it directly into the text field.

                    I've just pasted this...
                    Q1.text = playername +" , I hope you're enjoying to read";

                    into actions frame and tried this after changing the name of text field...

                    qone.text = "Greetings " + playername +" , I hope you're enjoying to read this simple acknowledgementge is and your social security number is of the fact that I know stuff about you. Your a. ";

                    Neither work. Seriously I am trying everything lol
                    • 7. Displaying Var With Other Text
                      Greg Dove Level 4
                      Ok.
                      1. Have your textfield in frame1 of layer 1. In the property panel make sure it says 'Dynamic Text' and immediately below that name it Q1 (it could be called message or whatever but let's leave it at Q1 for now to keep consistent with earlier posts).If you see a greyed out <Instance Name> then that's where you need to put the Q1

                      2. Create layer 2 if you don't already have one. Click on frame 1 of layer two. Open up the actionscript window (f9 in windows) and paste these 2 lines below in the actionscript window:

                      playername ="ZypheR2007";
                      Q1.text = playername+", I know your name."

                      3. In windows press Ctrl-enter or goto Control - Test Movie in the menu
                      • 8. Re: Displaying Var With Other Text
                        ZypheR2007 Level 1
                        That done it, I was putting the AC in the object (Text box) and not in a seperate frame.

                        Thanks a lot for your time
                        • 9. Re: Displaying Var With Other Text
                          ZypheR2007 Level 1
                          Theres obviously something I'm not getting, I can get that to work on a new flash but on my own flash it will not work.

                          Can it be to do with where I have a stop(); statement?
                          I thought I was about to make progress there and get on with making my flash! lol
                          • 10. Re: Displaying Var With Other Text
                            ZypheR2007 Level 1
                            It was the way I was testing it, I was using ENTER to move to the next frame on a page as I had not yet placed the button to move. Once I placed the button it worked fine.

                            Thanks again for your time
                            • 11. Re: Displaying Var With Other Text
                              Greg Dove Level 4
                              You're welcome.