5 Replies Latest reply on Apr 25, 2018 9:31 AM by ClayUUID

    Dynamic Text with Flash HTML5 (Canvas)

    djsegler Level 1

      I'm new to JS and need some help...

       

      I've generated a simple Flash HTML5 Canvas project that has a dynamic text field on the stage. How would I go about changing the value of the text within that element using JS commands elsewhere in the timeline?

       

      I've tried the following and none of them work:

       

      this.myTextBox.value = "blah blah";

      or

      this.myTextBox.value = ("blah blah");

      or

      this.myTextBox.txt = "blah blah"; // Since my dynamic text field linkage name is txt

      or

      this.myTextBox.txt.value = "blah blah";

      or

      this.myTextBox.txt.text = "blah blah";

       

      etc...

       

      What's the right syntax?

       

      Thanks!

        • 1. Re: Dynamic Text with Flash HTML5 (Canvas)
          djsegler Level 1

          Well - suddenly working now... Not sure what I did though...

           

          Here's what works:

           

          dynamic text field added to stage within a movieclip called "myTextBox" with text field labeled as "txt" inside the movieclip:

           

          this.myTextBox.txt.text = "blah blah";

           

          Now I'm happy.

           

          ;-)

          2 people found this helpful
          • 2. Re: Dynamic Text with Flash HTML5 (Canvas)
            JosephLabrecque Adobe Community Professional

            If it's only a bare Text object, it would be:

            this.myTextBox.text = "blah blah";

            1 person found this helpful
            • 3. Re: Dynamic Text with Flash HTML5 (Canvas)
              iqmactep

              Is this possible to do in Animate CC, have tried using the above and similar syntax, just as dynamic text as well as within a movieclip symbol but with no luck and wanted to check if possible before I go any further!

               

              Thanks, Matt

              • 4. Re: Dynamic Text with Flash HTML5 (Canvas)
                rocketeer61761

                If you have a dynamic text box on stage in Animate CC, you reference that text by using:

                 

                this.myTextBox.text = "type text here";

                 

                (change myTextBox in the code above to the instance name of your dynamic text box)

                 

                If you are referencing that same dynamic text box within a function, you will need to setup a global version of the this variable using something like an underscore this.:

                 

                var _this = this;

                 

                function typeText () {

                     _this.myTextBox.text = "type text here";

                }

                 

                Within the typeText function's execution context, Animate CC cannot locate a dynamic text box on the stage using this.myTextBox.text. Because the "this." inside of the function execution context doesn't refer to the stage.

                • 5. Re: Dynamic Text with Flash HTML5 (Canvas)
                  ClayUUID Adobe Community Professional

                  rocketeer61761  wrote

                   

                  If you are referencing that same dynamic text box within a function, you will need to setup a global version of the this variable using something like an underscore this.:

                  It depends on how you define the function. If you define it like this:

                   

                  function bla() {

                  }

                   

                  Then this becomes the root object when it's called (unless you use bind). On the other hand, if you define it like this:

                   

                  someObject.bla = function() {

                  }

                   

                  Then this will point to someObject when it's called.

                   

                  And no, you don't have to prefix a variable name with an underscore to make it global.