3 Replies Latest reply on Apr 19, 2013 8:56 AM by kglad

    text field into an emptymovieclip?

    JonnyDL Level 1

      I've been looking into trying to load text into an a dynamically created MC.

       

      I can create the empty movie-clip, and load a picture into it. I can create a text field and put text in it.

      I'm having a problem putting the text field into the movie clip. the code below is info I gathered and experimented with.

      I get the text on the stage and the picture loaded, but not the text into the mc

      (the x and y location was to see is the text moved with or without the movieclip.

       

      var mcBox = this.createEmptyMovieClip("mcHolder" , 3);

      var myLoader:MovieClipLoader = new MovieClipLoader();

       

      myLoader.loadClip("Pool.png", mcBox);

      var myText = infoBox.createTextField("myText", 1, 0, 0, 100, 100);

      myText.text = "SOME RANDOM TEXT HERE";

      mcBox._x=88;

      mcHolder._y=55;

       

       

      Can anyone help?

        • 1. Re: text field into an emptymovieclip?
          kglad Adobe Community Professional & MVP

          try:

           

           

          var mcBox = this.createEmptyMovieClip("mcHolder" , 3);

          var myLoader:MovieClipLoader = new MovieClipLoader();

           

          myLoader.loadClip("Pool.png", mcBox);

          myLoader.addListener(this);

           

          this.onLoadInit=function(mc:MovieClip){

          var myText:TextField = mcBox.createTextField("myText", 1, 0, 0, 100, 100);

          myText.text = "SOME RANDOM TEXT HERE";

          mcBox._x=88;

          mcBox._y=55;

          }
          • 2. Re: text field into an emptymovieclip?
            JonnyDL Level 1

            Thanks, it worked of course. Though Im having a bit of a trouble maling sence of it, and I hope you could give me a breif clarification.

            Not sure why the onloadint needs to be used, and the use of "this" (this concept always troubles me at what it is referencing).

             

            My understanding: you need/want to use the onloadinit to detect when the load of the first image(object) is started(initalized). [Could it work without it? I tried combinations and I couldn't]. The onloadint it is an (inline) function so it needs something to activate it, and thats the addlistener. In this case it is lisenting to all activites of the myloader specifically [loadclip of the image"pool" into mcBox -> (this)], and when the load is initailized it then places the text.

             

                thanks for you contributions, helping the rest of us grow with the language

            • 3. Re: text field into an emptymovieclip?
              kglad Adobe Community Professional & MVP

              when loading completes/initializes, everything that was in the load target (mcBox) is replaced.  so, if you add a textfield, or anything else, before loading completes, it will be replaced by the object loaded (Pool.png).

               

              so, you need to use onLoadInit (and you may be able to use onLoadComplete).

               

              addListener accepts an object that's used to define the scope of the listener's methods (like onLoadInit).  so, instead of "this", you could also use:

               

              var mcBox = this.createEmptyMovieClip("mcHolder" , 3);

              var myLoader:MovieClipLoader = new MovieClipLoader();

               

              myLoader.loadClip("Pool.png", mcBox);

               

              var obj:Object={};

              myLoader.addListener(obj);

               

              obj.onLoadInit=function(mc:MovieClip){

              var myText:TextField = mcBox.createTextField("myText", 1, 0, 0, 100, 100);

              myText.text = "SOME RANDOM TEXT HERE";

              mcBox._x=88;

              mcBox._y=55;

              }