12 Replies Latest reply on Feb 13, 2012 4:58 PM by kglad

    How can I get text in a dynamic text field to be a "button"

    subtlefly72 Level 1

      Hi team,

      I have a project that has a heap of variables that I have created for workd definitions.  I have made a dynamic text box so it just loads up the correct text from the variable.

      NOW, question is I want to use a listener? (A href?) to know if the user is clicking on a word inside the dynamic text box.

      There are some words in some of the definitions that I hav also written separate variables and definitions for.  e.g. in the definition for promotion

      var w5="Promotions";

      var def5="Promotions are where your business tries to increase the sales of a particular item through offering a good deal, advertising or a special display.";

      There is the word advertising, I want to call a function that will then bring up the variable for advertisiing and so change the text in the dynamic textbox

       

      I see some examples online but I can't understnad them adn they are using html or xml from an external document (I think?)

      Please help!

      Here are the important bits of code (please don't hurt yourself laughing)

      var w5="Promotions";

      var def5="Promotions are where your business tries to increase the sales of a particular item through offering a good deal, advertising or a special display.";

      function showdefinitions(){

                worddefinitions.play();

        wordDEF.text=ans1;

        Def_word_1.text=ans2;

                wordDEF.visible=true;

        Def_word_1.visible=true;

      Object(this.parent).defbackup.visible=false;

      }

      Object(this).promotions_def.addEventListener(MouseEvent.CLICK, showpromotions);

      function showpromotions(event:MouseEvent):void {

       

       

         ans1=def5;

         ans2=w5;

                showdefinitions();

       

      }

       

      Can this be done?

      Cheers

      sub

        • 1. Re: How can I get text in a dynamic text field to be a "button"
          kglad Adobe Community Professional & MVP

          use the textfield link event.

          1 person found this helpful
          • 2. Re: How can I get text in a dynamic text field to be a "button"
            subtlefly72 Level 1

            yeh thanks but i just can't understand the examples that I can find- they are using HTML text and I have got text in a variable, does it matter?  I can't seem to find the bit where you identify the bit of text that you want to be clickable.
            Sorry to be such an idiot, can you point me toward some easily understandable example?

            Cheers

            • 3. Re: How can I get text in a dynamic text field to be a "button"
              kglad Adobe Community Professional & MVP

              you'll need to use your keyword string and text string and the desired action to convert your text string into a html string that does what you want.  i don't know any simple way to do that.  it's doable but will take some time.

               

              the basic idea is something like:

               

              var w5="Promotions";  // this is to be the keyword linked to something

              var def5="Promotions are where your business tries to increase the sales of Promotions a particular item through offering a good deal, advertising or a special display Promotions";  // and this is the text to be displayed that should treat all w5 instances as links

              var data5="d5";

               

              this.addEventListener(TextEvent.LINK,linkF);  // this line can be used for all your textfields, if you have more than one.

              yourtextfield.htmlText=parseTextF(w5,def5,data5);

               

              function parseTextF(keyword:String,txt:String,dataS:String):String{

              // i think you'll need to consider 3 cases.  1. a keyword is at the start, 2. in the middle , 3. at the end of txt

              // for example: if 1:

              var a:Array=txt.split(keyword);

              return = "<a href='event:"+dataS+"'>"+keyword+"</a>+a[1]";

              // and you may have more than 1 keyword in txt

              }

               

              function linkF(e:TextEvent):void{

              // do something using e.text which will = data

              }

              1 person found this helpful
              • 4. Re: How can I get text in a dynamic text field to be a "button"
                subtlefly72 Level 1

                Hey kglad thanks for putting in the time and trying

                but I am still having trouble getting it to work

                I am thinking that..

                1) keyword is meant to be changed to the target word I am looking for i.e. advertising

                2) yourtextfield needs to be the instance name of the dynamic text box i.e.  wordDEF

                 

                I am getting a expecting identifier before assign error on the line with return

                 

                I am really trying to get this to work, but having massive problems understanding how the code is working,

                sorry

                Thanks again for taking the time

                • 5. Re: How can I get text in a dynamic text field to be a "button"
                  kglad Adobe Community Professional & MVP

                  try:

                   

                  var w5="Promotions";  // this is to be the keyword linked to something

                  var def5="Promotions are where your business tries to increase the sales of a particular item through offering a good deal, advertising or a special display.";  // and this is the text to be displayed that should treat all w5 instances as links

                  var data5="d5";

                   

                  this.addEventListener(TextEvent.LINK,linkF);  // this line can be used for all your textfields, if you have more than one.

                  tf.htmlText=parseTextF(w5,def5,data5);

                   

                  function parseTextF(keyword:String,txt:String,dataS:String):String{

                  // i think you'll need to consider 3 cases.  1. a keyword is at the start, 2. in the middle , 3. at the end of txt

                  // for example: if 1:

                  var a:Array=txt.split(keyword);

                  return "<a href='event:"+dataS+"'>"+keyword+"</a>"+a[1];

                  // and you may have more than 1 keyword in txt

                  }

                   

                  function linkF(e:TextEvent):void{

                  trace(e.text);

                  }

                  1 person found this helpful
                  • 6. Re: How can I get text in a dynamic text field to be a "button"
                    subtlefly72 Level 1

                    Hey thanks for taking the time, I really appreciate it,

                     

                    just to check that i understand,  Your line here

                    var w5="Promotions";  // this is to be the keyword linked to something

                    does thhis mean that var w5 is the keyword?  So keyword isnt a placeholder that needs to be changed to the word promotions or advertising or whatever??

                     

                    Also I see txt in the code? does this stay also or does it need to be changed to something else?

                     

                    Thanks I really really need this help and love your work,

                    I will try the new code and let you know how I go

                    • 7. Re: How can I get text in a dynamic text field to be a "button"
                      kglad Adobe Community Professional & MVP

                      w5 is a keyword that you want to use as a link in def5.  data5 is used in linkF to determine what action you want taken when the keyword w5 in def5 is clicked.

                       

                      nothing needs to be changed in my message 5 code.   the parameters in parseTextF() don't need to match w5,def5,data5.

                      1 person found this helpful
                      • 8. Re: How can I get text in a dynamic text field to be a "button"
                        subtlefly72 Level 1

                        I love you so much you are the greatest!

                        It is working and I can see a trace, d5 on click!

                        I think I will be able to make it function from here,

                        I am very very happy with that,

                        Thankyou

                        • 9. Re: How can I get text in a dynamic text field to be a "button"
                          subtlefly72 Level 1

                          Hey so I have got a basic idea of how it works, I actually wanted to link the word advertising from that promotions text so I have changed the w5 to "advertising" in the  code,

                          wordDEF.htmlText=parseTextF("advertising",def5,data5);

                          It works, but now it is cutting the text so that advertising is the first word,

                          // i think you'll need to consider 3 cases.  1. a keyword is at the start, 2. in the middle , 3. at the end of txt

                          // for example: if 1:

                          var a:Array=txt.split(keyword);

                          return "<a href='event:"+dataS+"'>"+keyword+"</a>"+a[1];

                           

                          so if I can't work this out on my own do you mind if I come back and ask for more help?

                          • 10. Re: How can I get text in a dynamic text field to be a "button"
                            kglad Adobe Community Professional & MVP

                            use:

                             

                            function parseTextF(keyword:String,txt:String,dataS:String):String {

                                // i think you'll need to consider 3 cases.  1. a keyword is at the start, 2. in the middle , 3. at the end of txt

                                // for example: if 2

                                var a:Array = txt.split(keyword);

                                return a[0]+"<a href='event:"+dataS+"'>"+keyword+"</a>"+a[1];

                                // and you may have more than 1 keyword in txt

                            }

                             

                             

                            p.s.  please mark helpful/correct responses, if there are any.