4 Replies Latest reply on Aug 9, 2010 11:49 PM by slugger_2003

    Animating a dynamic textbox by converting it to a movie clip

    slugger_2003

      Hi all.

       

      I have been trying to create a die that acts as a 60 second timer in Flash CS4 using Actionscript 3.0. This involves creating a die and a dynamic textbox that counts from 60 to 0. Both of these parts of the project are fine, however I need to animate the textbox in 3D space to coincide with the die rolling. I believe it is not possible to animate a textbox (from online reading and also trying to do it myself by playing about with Flash) so I have loaded the textbox into a movieclip. As I'm having issues with this I thought it would be good practice to split the project into sub-projects in order to identify the problem. Here is the actionscript 3.0 I have used for the timer/countdown clock:

       

       

      var newTime:Loader = new Loader();

       

      newTime.load(new URLRequest("SWFs/timer.swf"));

      clock_mc.addChild(newTime); //clock_mc is an instance of movieClipContainer which is a new movie clip I created in this project which is simply a                                              60*60 square with a black stroke and blank fill.

       

       

      Here is a screenshot of the timeline:

       

      ScreenShot005.png

      When I try to do this, everything is fine, however when I try to animate the timer, this happens:

       

       

      I have also tried changing the length of the AS3 layer to be a single frame but this makes no difference.

      When the movie clip is not animated, the timer works fine, no text overlay. Any thoughts on how to fix this? Have I forgotten something basic or stumbled across an error in Flash CS4?

        • 1. Re: Animating a dynamic textbox by converting it to a movie clip
          kglad Adobe Community Professional & MVP

          why are you loading a swf?  (and, you almost certainly don't want to repeatedly load anything.)

          • 2. Re: Animating a dynamic textbox by converting it to a movie clip
            slugger_2003 Level 1

            I am loading an SWF as it's the format of the timer project that contains the dynamic text field that counts down from 60 to 0....

            I would create this in a single project however it also has to animate...hence, has to be a movieclip....but the contents of the movieclip can't act like a dynamic textfield.....to the best of my knowledge....no?

            • 3. Re: Animating a dynamic textbox by converting it to a movie clip
              kglad Adobe Community Professional & MVP

              no.

               

              you can animate your textfield without converting it to a movieclip.  but there are somethings (like add filters) you can't do to a textfield and you can do to a movieclip.  in that situation, you would create a new movieclip and add a textfield to the movieclip (which is the same thing as right clicking your textfield that's on-stage, clicking convert to symbol and ticking movieclip).

               

              in your situation, there's no reason to load a swf.  and there's certainly no reason to repeatedly load it and cause that display with on numbers on top of other numbers ad infinitum.

               

              so, create a movieclip and place a textfield on its first frame.  assign an instance name to that textfield (eg, tf).  animate the textfield the way you want.  at the end of your movieclip's timeline (where your animation ends and the textfield's display is no longer needed) insert a blank keyframe and attach

               

              stop();

              this.parent.removeChild(this);

               

              to it.

               

              find the movieclip in your library, right click and tick export for actionscript and assign a class (eg, TFmc).  you can then use something like the following:

               

              ///////////////////////////// call startCountdown() whenever you want to start a countdown timer //////////////////////////////

               

              function startCountdown():void{

              timer.start();

              }

               

              ///////////////////////// call stopCountdown() whenever you want to stop a countdown timer ////////////////////////////////

               

              function stopCountdown():void{

              timer.stop();

              }

               

              ///////////////////////////// leave below alone ///////////////////////////////

               

              var timer:Timer = new Timer(1000,0);

              timer.addEventListener(TimerEvent.TIMER,textF);


              function textF(e:TimerEvent):void{

              var mc:MovieClip=new TFmc();

              addChild(mc);

              mc.tf.text = 60-e.target.currentCount;

              if(e.target.currentCount==60){

              e.target.reset();

              }

              }

              • 4. Re: Animating a dynamic textbox by converting it to a movie clip
                slugger_2003 Level 1

                How do you 'add a textfield to a movieclip'? I'm assuming this is done as you say, by right clicking on the textfield, right clicking convert to symbol then selecting 'movieclip' from the Type drop down menu and clciking OK?

                Once I've done this, the textbox no longer exists as it's been converted to a movieclip...before the textbox was referred to as time_text, now it is an instance of the movieclip in the library...so the dynamic textbox is not IN a movieclip, it has been converted TO a movieclip as the option suggests....so I'm confused by your instructions....no textfields exist in the project now, there is only the movieclip that used to be the textfield and is now converted into a movieclip....

                Following on with your instructions I get the error:

                 

                TypeError: Error #1010: A term is undefined and has no properties.

                 

                This refers to the line:

                 

                mc.tf.text = 60-e.target.currentCount;

                 

                I believe this is because mc.tf does not exist.....mc exists as an instance of the object in the library and tf exists on the stage but tf is not IN the moveiclip, it is not a child of mc.....

                 

                Thanks.