19 Replies Latest reply on Nov 29, 2007 10:32 AM by jl2000

    createTextField function question

    jl2000 Level 1
      Hi - I think what I'm trying to do is fundamental but I'm not doing it correctly.
      I have a swf that has a few different textFields appearing when buttons are clicked. I thought I could write one function that would handle the creation of all the textFields so that I could just put a few parameters into the function call at the onRelease.

      So is there a way to make this code into a function (like "makeTF") such that I could replace "block_txt" with any string I want and call the function like : makeTF(AnyString, depth, 110,90, 200,60);
      ??

      I appreciate any help with this.
      jl
        • 2. Re: createTextField function question
          brycebarrand
          Try this:


          var tf = makeTF("hey world", "1_tf", 0, 0, 100, 20);

          function makeTF(newText:String, id:String, x:Number, y:Number, width:Number, height:Number):TextField{
          var newTf = this.createTextField(id,this.getNextHighestDepth,x,y,width,height);
          newTf.text = newText;
          return newTf;
          }
          • 3. Re: createTextField function question
            jl2000 Level 1
            brycebarrand -

            Thanks.

            I'm not sure how to call this.
            When I put your code on fr1 and then called it on fr10 using different text in the quotes - all I got was your "hey world" from fr1 and not my text. I'll be calling this numerous times with different text.

            How can I make this work as you intended?

            TIA your help.
            jl
            • 4. Re: createTextField function question
              jl2000 Level 1
              Hi kglad,
              Thanks for the response. This isn't sinking in. I put your code on fr1 and called it on frame 10 with the code below. All I got on the screen was a thin horizontal line about 40px long.

              Did you intend for me to add anything to your code? What am I missing?

              Thanks again,
              JL
              • 5. Re: createTextField function question
                kglad Adobe Community Professional & MVP
                you're missing the string for the textfield's _name property.
                • 6. Re: createTextField function question
                  jl2000 Level 1
                  Kglad -

                  Got it!

                  Thanks.
                  jl
                  • 7. createTextField function question
                    jl2000 Level 1
                    hmmm
                    • 8. Re: createTextField function question
                      kglad Adobe Community Professional & MVP
                      you're welcome.
                      • 9. Re: createTextField function question
                        jl2000 Level 1
                        kglad - I'm always trying to understand more about coding so I hope you don't mind a question or two. I understand "s:String" on line 1 and how "s" is used in line 2 but I don't know "with (this[s])" means. What's going on here?

                        Also - a weird thing - when I put your code into the actionscript window the syntax coloring went off such that some of the statements under "with (this[s])" are all blue and some are not. Is there something I can learn from that?

                        Thanks for your instruction.
                        JL

                        • 10. Re: createTextField function question
                          kglad Adobe Community Professional & MVP
                          array notation is used by flash to convert strings to objects. so, while s is a string this[s] is an object (the textfield with instance name s).

                          and the only thing i infer from some properties being highlighted in blue and others not, is that the flash compiler is less than flawless.
                          • 11. Re: createTextField function question
                            jl2000 Level 1
                            kglad -
                            I think I get it - that anything in square brackets is an array. (its the simple things that mean so much).

                            As far as the flash compiler - you're being modest. You just brought it beyond the limits of its function...nice work!

                            Thanks for all the coaching.

                            jl
                            • 12. Re: createTextField function question
                              kglad Adobe Community Professional & MVP
                              you're welcome.
                              • 13. Re: createTextField function question
                                jl2000 Level 1
                                Hi kglad -
                                Something has come up when using this function.

                                What I have is 3 btns. When a btn is rolled over, it uses attachMovie to bring in it's "info_panel". The info panel is a movie clip with a background and a textField On info_panel1 the TF is created using the function makeTF().
                                So - rolling over btn1 attaches info_panel1. Then rolling over btn2 will attach i_p2 -which then should replace i_p1.

                                The problem is that the textField created with the function makeTF() on info_panel1 stays in place when other info panels are attached. The background of info_panel1 goes away, but the TF stays visible and refuses to be replaced by another attached mc on the stage.

                                Must I use some code to remove the TF created with makeTF() ?

                                I hope this makes sense. TIA for your help.

                                JL






                                • 14. Re: createTextField function question
                                  kglad Adobe Community Professional & MVP
                                  change makeTF() so it accepts a movieclip parameter. that movieclip will be the one upon which you want to attach the textfield. then inside your function body use that movieclip parameter instead of "this".
                                  • 15. Re: createTextField function question
                                    jl2000 Level 1
                                    kglad - thanks for the reply. The only thing I think I understand is "change makeTF() so it accepts a movieclip parameter. "
                                    So I added "basemc:MovieClip" within the parens. That's as much as I thought I was sure of.

                                    "that movieclip will be the one upon which you want to attach the textfield." is where I stop understanding because of the word "attach". But I persist anyway.

                                    "then inside your function body use that movieclip parameter instead of "this". "
                                    So - inside the function body I see:
                                    this.createTextField(s,dep,x,y,w,h);
                                    ....and I replace that with:
                                    basemc.createTextField(s,dep,x,y,w,h);

                                    This sort of make sense until I go to the place where the function call actually sits. The "makeTF()" call goes on the actions layer on the movie clip "info_panel1" (because that's the mc upon which I want to ....) so it looks like:
                                    info_panel1.makeTF("<h1> This is INFO.</h1>","tf_panel1",99,40,250,370,140);
                                    ... and the text doesn't show at all.

                                    BTW: otherwise the call I was using looked like this:
                                    _root.makeTF("<h1> This is INFO.</h1>","tf_panel1",99,40,250,370,140);
                                    ...but that's the code that didn't go away when another mc was attached.

                                    Where did I misunderstand?

                                    jl









                                    • 16. Re: createTextField function question
                                      kglad Adobe Community Professional & MVP
                                      if your second parameter is the movieclip instance name, don't put that in quotes. if have any trouble after fixing that, show your updated makeTF() function and your function call (using the attach code option).
                                      • 17. Re: createTextField function question
                                        jl2000 Level 1
                                        kglad - basemc is the new parameter. I've been playing around with the different combinations of "this", "basemc", & "panel_info1" - but I'm just making things worse. With the attached code I'm not getting the textField at all. When I started I was getting the TF - it just wouldn't go away. I guess I added the parameter wrong in the first place but I don't know of any other way.
                                        jl
                                        • 18. Re: createTextField function question
                                          kglad Adobe Community Professional & MVP
                                          you didn't replace all occurrences of "this" with basemc and your function call is incorrect:

                                          • 19. Re: createTextField function question
                                            jl2000 Level 1
                                            kglad -
                                            I'm getting a msg when I rollOver the btn that brings in panel_info1 (attachMovie);
                                            "Error: A 'with' action failed because the specified object did not exist."

                                            My excuse for not replacing the "this" in "with (this[s])" is because I thought that it referred to the textField being created and not the movieClip it was going in to. Just an excuse mind you.

                                            I also tried putting the function right above the code for the call ...on the same layer in panel_info1. I got the same message on rollOver. Then I tried putting the function and the call on the root layer and got the same msg on loading the swf. What should I try next?

                                            jl