10 Replies Latest reply: Apr 15, 2012 10:33 PM by kglad RSS

    New to Actionscript 3

    rleach26

      I am new to actionscript 3.  I have text appearing in a text field with the appearence of a typewriter effect. How do I write the code so that present text after a 3 second delay is replaced by new text?

        • 1. Re: New to Actionscript 3
          kglad CommunityMVP

          use a timer.  i assume you have a function (eg, twEffectF) or class that accepts the text you want displayed with that effect and accepts the textfield (eg, tf) where you want that displayed.  if so, use:

           

          var textA:Array=["first string to display","next string","last string"] ;

          var t:Timer=new Timer(3000,0);

          t.addEventListener(TimerEvent.TIMER,timerF);

          t.start();

           

          function timerF(e:TimerEvent):void{

          tsEffectF(tf,textA[(Timer(e.currentTarget).repeatCount-1)%textA.length]);

          }

          • 2. Re: New to Actionscript 3
            rleach26 Community Member

            Thanks for the quick response. This is the code I have so far var myString:String = "You cannot stop a Tornado."; var myArray:Array = myString.split("");

            addEventListener(Event.ENTER_FRAME,frameHandler);

            function frameHandler(event:Event):void{

             

              if(myArray.length > 0) {

               textField.appendText(myArray.shift());

                

              }

              else

              {

               removeEventListener(Event.ENTER_FRAME, frameHandler);

                

              textField.text="";

              }

                }

            Date: Sat, 14 Apr 2012 10:40:27 -0600

            From: forums@adobe.com

            To: rickleach1@hotmail.com

            Subject: New to Actionscript 3

             

             

             

             

             

             

                  

                       

                       

                       

                Re: New to Actionscript 3

             

             

                created by kglad in Flash Pro - General - View the full discussion

             

             

             

            use a timer.  i assume you have a function (eg, twEffectF) or class that accepts the text you want displayed with that effect and accepts the textfield (eg, tf) where you want that displayed.  if so, use: var textA:Array=["first string to display","next string", "last string"];var t:Timer=new Timer(3000,0);t.addEventListener(TimerEvent.TIMER,timerF);t.start(); function timerF(e:TimerEvent):void{tsEffectF(tf,textA[Timer(e.currentTarget).repeatCount%textA.len gth]);}

             

             

                 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4334865#4334865

                 To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4334865#4334865. In the Actions box on the right, click the Stop Email Notifications link.

                  

                 Start a new discussion in Flash Pro - General by email or at Adobe Forums

              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

            • 3. Re: New to Actionscript 3
              rleach26 Community Member

              Oh and more important than the timer I would like to know what code I need to add so that I can replace the typewriter effect text with new text after a 3 second delay.  Thanks for all your help! rleach

              Date: Sat, 14 Apr 2012 10:40:27 -0600

              From: forums@adobe.com

              To: rickleach1@hotmail.com

              Subject: New to Actionscript 3

               

               

               

               

               

               

                    

                         

                         

                         

                  Re: New to Actionscript 3

               

               

                  created by kglad in Flash Pro - General - View the full discussion

               

               

               

              use a timer.  i assume you have a function (eg, twEffectF) or class that accepts the text you want displayed with that effect and accepts the textfield (eg, tf) where you want that displayed.  if so, use: var textA:Array=["first string to display","next string", "last string"];var t:Timer=new Timer(3000,0);t.addEventListener(TimerEvent.TIMER,timerF);t.start(); function timerF(e:TimerEvent):void{tsEffectF(tf,textA[Timer(e.currentTarget).repeatCount%textA.len gth]);}

               

               

                   Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4334865#4334865

                   To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4334865#4334865. In the Actions box on the right, click the Stop Email Notifications link.

                    

                   Start a new discussion in Flash Pro - General by email or at Adobe Forums

                For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

              • 4. Re: New to Actionscript 3
                kglad CommunityMVP

                use:

                 

                 

                var textA:Array=["first string to display","next string","last string"] ;

                var t:Timer=new Timer(3000,0);

                t.addEventListener(TimerEvent.TIMER,timerF);

                t.start();

                 

                function timerF(e:TimerEvent):void{

                twEffectF(textA[(Timer(e.currentTarget).repeatCount-1)%textA.length ]);

                }

                function twEffect(s:String):void{

                textField.text="";

                this.myArray=s.split("");

                addEventListener(Event.ENTER_FRAME,frameHandler);

                }

                 

                function frameHandler(event:Event):void{

                 

                  if(myArray.length > 0) {

                   textField.appendText(myArray.shift());

                   

                  }

                  else

                  {

                   removeEventListener(Event.ENTER_FRAME, frameHandler);

                   

                  textField.text="";

                  }

                    }

                • 5. Re: New to Actionscript 3
                  rleach26 Community Member

                  Hey thanks again for all your help.  Unfortunately the code you sent does not work.  I think its the twEffect (I assume you mean typewriter effect) that is in the code that is causing the problem.    Here is the original code that works which types out the one line of text "You cannot stop a Tornado."

                   

                  var myString:String = "You cannot stop a Tornado.";

                  var myArray:Array = myString.split("");          //seperates each letter which creates the typewriter effect.

                   

                   

                  addEventListener(Event.ENTER_FRAME,frameHandler);

                  function frameHandler(event:Event):void{

                   

                    if(myArray.length > 0) {

                     textField.appendText(myArray.shift());

                      

                    }

                    else

                    {

                    removeEventListener(Event.ENTER_FRAME, frameHandler);

                    textField.text="";

                    }

                   

                  }

                   

                   

                   

                   

                   

                  Date: Sat, 14 Apr 2012 16:11:25 -0600

                  From: forums@adobe.com

                  To: rickleach1@hotmail.com

                  Subject: New to Actionscript 3

                   

                   

                   

                   

                   

                   

                        

                             

                             

                             

                      Re: New to Actionscript 3

                   

                   

                      created by kglad in Flash Pro - General - View the full discussion

                   

                   

                   

                  use:  var textA:Array=["first string to display","next string","last string"] ;var t:Timer=new Timer(3000,0);t.addEventListener(TimerEvent.TIMER,timerF);t.start(); function timerF(e:TimerEvent):void{twEffectF(textA[(Timer(e.currentTarget).repeatCount-1)%textA.le ngth ]);}function twEffect(s:String):void{textField.text="";this.myArray=s.split("");addEventListener(Event .ENTER_FRAME,frameHandler);}  function frameHandler(event:Event):void{    if(myArray.length > 0) {   textField.appendText(myArray.shift());      }  else  {   removeEventListener(Event.ENTER_FRAME, frameHandler);       textField.text="";  }    }

                   

                   

                       Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4335223#4335223

                       To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4335223#4335223. In the Actions box on the right, click the Stop Email Notifications link.

                        

                       Start a new discussion in Flash Pro - General by email or at Adobe Forums

                    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                  • 6. Re: New to Actionscript 3
                    kglad CommunityMVP

                    use:

                     

                    var textA:Array=["first string to display","next string","last string"];

                    var myArray:Array = [];

                    var t:Timer=new Timer(3000,0);

                    t.addEventListener(TimerEvent.TIMER,timerF);

                    t.start();

                     

                    function timerF(e:TimerEvent):void {

                        twEffectF(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ]);

                    }

                    function twEffectF(s:String):void {

                        trace(1,s,2)

                        textField.text="";

                        myArray=s.split("");

                        addEventListener(Event.ENTER_FRAME,frameHandler);

                    }

                     

                    function frameHandler(event:Event):void {

                        if (myArray.length>0) {

                            textField.appendText(myArray.shift());

                        } else {

                            removeEventListener(Event.ENTER_FRAME, frameHandler);

                            textField.text="";

                        }

                    }

                     

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

                    • 7. Re: New to Actionscript 3
                      rleach26 Community Member

                      Hey, Thanks a lot!  it works. rleach

                      Date: Sun, 15 Apr 2012 08:26:55 -0600

                      From: forums@adobe.com

                      To: rickleach1@hotmail.com

                      Subject: New to Actionscript 3

                       

                       

                       

                       

                       

                       

                            

                                 

                                 

                                 

                          Re: New to Actionscript 3

                       

                       

                          created by kglad in Flash Pro - General - View the full discussion

                       

                       

                       

                      use: var textA:Array=["first string to display","next string","last string"];var myArray:Array = [];var t:Timer=new Timer(3000,0);t.addEventListener(TimerEvent.TIMER,timerF);t.start(); function timerF(e:TimerEvent):void {    trace(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ])    twEffectF(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ]);}function twEffectF(s:String):void {    trace(1,s,2)    textField.text="";    myArray=s.split("");    addEventListener(Event.ENTER_FRAME,frameHandler);} function frameHandler(event:Event):void {    if (myArray.length>0) {        textField.appendText(myArray.shift());    } else {        removeEventListener(Event.ENTER_FRAME, frameHandler);        textField.text="";    }} p.s.  please mark helpful/correct responses, if there are any.

                       

                       

                           Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4335963#4335963

                           To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4335963#4335963. In the Actions box on the right, click the Stop Email Notifications link.

                            

                           Start a new discussion in Flash Pro - General by email or at Adobe Forums

                        For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                      • 8. Re: New to Actionscript 3
                        kglad CommunityMVP

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

                        • 9. Re: New to Actionscript 3
                          rleach26 Community Member

                          here is another problem I incountered which I thought I would be able so solve easily.  After the string plays through ( last set of text) it loops.  How do I get it to play once and stop.  I tried a couple of ways.  I tried a stop function and the I tried adding a complete addEventListiner.  I could not get it to work. Again, thanks for all your help! rleach

                          Date: Sun, 15 Apr 2012 08:26:55 -0600

                          From: forums@adobe.com

                          To: rickleach1@hotmail.com

                          Subject: New to Actionscript 3

                           

                           

                           

                           

                           

                           

                                

                                     

                                     

                                     

                              Re: New to Actionscript 3

                           

                           

                              created by kglad in Flash Pro - General - View the full discussion

                           

                           

                           

                          use: var textA:Array=["first string to display","next string","last string"];var myArray:Array = [];var t:Timer=new Timer(3000,0);t.addEventListener(TimerEvent.TIMER,timerF);t.start(); function timerF(e:TimerEvent):void {    trace(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ])    twEffectF(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ]);}function twEffectF(s:String):void {    trace(1,s,2)    textField.text="";    myArray=s.split("");    addEventListener(Event.ENTER_FRAME,frameHandler);} function frameHandler(event:Event):void {    if (myArray.length>0) {        textField.appendText(myArray.shift());    } else {        removeEventListener(Event.ENTER_FRAME, frameHandler);        textField.text="";    }} p.s.  please mark helpful/correct responses, if there are any.

                           

                           

                               Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4335963#4335963

                               To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4335963#4335963. In the Actions box on the right, click the Stop Email Notifications link.

                                

                               Start a new discussion in Flash Pro - General by email or at Adobe Forums

                            For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                          • 10. Re: New to Actionscript 3
                            kglad CommunityMVP

                            use:

                             

                            var textA:Array=["first string to display","next string","last string"];

                            var myArray:Array = [];

                            var t:Timer=new Timer(3000,textA.length);

                            t.addEventListener(TimerEvent.TIMER,timerF);

                            t.start();

                             

                            function timerF(e:TimerEvent):void {

                                twEffectF(textA[(Timer(e.currentTarget).currentCount-1)%textA.length ]);

                            }

                            function twEffectF(s:String):void {

                                trace(1,s,2)

                                textField.text="";

                                myArray=s.split("");

                                addEventListener(Event.ENTER_FRAME,frameHandler);

                            }

                             

                            function frameHandler(event:Event):void {

                                if (myArray.length>0) {

                                    textField.appendText(myArray.shift());

                                } else {

                                    removeEventListener(Event.ENTER_FRAME, frameHandler);

                                    textField.text="";

                                }

                            }

                             

                            p.s.  you should mark the actual correct and helpful answers, not just any response of mine.  other people use those as shortcuts to find answers quickly, especially the correct answer which is linked in your original post.