3 Replies Latest reply on May 6, 2008 11:15 AM by minzojian

    problem of defining value to a textfield in MovieClip

    minzojian
      hello,dear everyone
      there is problem that realy confused me.that is the textfield(or other display objects) in MovieClip can't be defined when i jumpto that frame.check these simple code:

      mc.stop()
      function goNext(evt:Event){
      mc.nextFrame()
      dosth()
      }
      function dosth()
      {
      if(mc.currentFrame==2)
      {
      mc.mytext.text="hello"
      }
      }
      nextBT.addEventListener("click",goNext)


      the mc is a simple MC that have 2 frames,and the textfield object is in the second frame.
      and what i try to do is when i clicked the button,the mc jumpto the second frame.and i define a value to that textfield.but it's failed when i try to do like that.
      as i debug the program.i found that when i define the value to the textfield,that textfield is a Null Object(should be the TextField object).not only the textfield not work,but also other elements such as Button objects.
      so,i am thinking that must because the objects are too late to initialized before they be used.maybe there are some event can tell me that all elements has been initialized,as i can use them then.what do you think,my friend?
        • 1. Re: problem of defining value to a textfield in MovieClip
          Ned Murphy Adobe Community Professional & MVP
          If all of the code you have is in the first frame, then it has processed long before anything ever moved to the second frame.

          What you could try is to have a variables layer that extends both frames, and assign the value of the textfield text to that variable. Make the textfield associate with that variable (in the properties section for it), So when the movieclip moves to the second frame the text field should automatically acquire the variable value.

          I may not have interpretted your problem correctly, so you might have to clarify things if I missed the target.
          • 2. Re: problem of defining value to a textfield in MovieClip
            minzojian Level 1
            thanks Ned,it could be a good solution for AS1 or AS2,but textfield variable property is not supported in AS3 anymore.so,i am thinking as if i have to add a Timer object to make a short delay till the objects initialized completely. or any other bright ideas?
            • 3. problem of defining value to a textfield in MovieClip
              minzojian Level 1
              at last,i have to use thes delay method to solove this problem.
              code like this.

              import flash.utils.Timer;
              import flash.events.*;
              mc.stop()
              var tim:Timer=new Timer(0);
              tim.addEventListener(TimerEvent.TIMER,dosth)
              function goNext(evt:Event){
              mc.nextFrame()
              tim.start()
              }
              function dosth(evt:Event)
              {
              if(mc.currentFrame==2)
              {
              mc.mytext.text="hello"
              }
              }
              nextBT.addEventListener("click",goNext)