14 Replies Latest reply on Feb 3, 2011 7:06 PM by gross770

    I found this cute swf file

    gross770 Level 1

      Hi

      I found this cute swf file.

      Would anyone now how to make this including the code for it in the FLA file?


      http://arongross.com/misc/wave-collor-letters.swf  I get the impression that this wouldn't be to hard.  I imagine you have to just type up the letters in your fla file and then maybe some how set them to blink either in the code or in the actual text on the time line.  Not sure?

       

      best regards,

      Aron

        • 1. Re: I found this cute swf file
          Ned Murphy Adobe Community Professional & MVP

          They are not blinking , they are individual textfields changing color, sequencially, probably at the frame rate of the file, using as many colors as there are letters.  One approach could be to just do this on the timeline and have the thing continuously loop.

           

          Alternatively, a coded approach could be taken.  Here's some code that can do it for a textfield with an instance name of tf...

           

          var colors:Array = new Array(0xFF0000,0x00FF00,0x0000FF,0xFF00FF,0xFFFF00,0x0000FF);

           

          var i:uint = 0;

           

          function changeColor(evt:Event):void {
              tf.textColor = colors[i];
              i+=1;
              if(i==colors.length){
                 i=0;
              }
          }

           

          stage.addEventListener(Event.ENTER_FRAME, changeColor);

          1 person found this helpful
          • 2. Re: I found this cute swf file
            gross770 Level 1

            HI Ned

            I tried it and it works for all the letters in one shot.  How would you do this for individual letters.  And is there a simple way to do it inside the time line.  Is there some feature inside flash that lets you choose a blink function of some sort?

             

            best regards,

            Aron

            • 3. Re: I found this cute swf file
              Ned Murphy Adobe Community Professional & MVP

              The coded approach would have separate textfields for each letter.  So that's how you you do it for individuals letters.

               

              For the timeline approach, just place the whole word in a static textfield in a keyframe and color each letter differently.  Then copy that to the next frame and change/shift the colors of each letter, and so on, until you have as many frames as you do letters in the word.

              • 4. Re: I found this cute swf file
                gross770 Level 1

                HI Ned,

                I'm a bit lost eventhough I know I'm so close to getting it right.  I have a problem in the logic of my code. Could you please tell me where I'm going wrong.  And here is a link to the swf file http://arongross.com/misc/Blinking2.swf

                 

                and here is my not quiet right code I have created a seperate name for each letter of the text - tf0, tf1 etc.

                 

                var colors:Array = new Array(0xFF0000,0x00FF00,0x0000FF,0xFF00FF,0xFFFF00,0x0000FF);
                var letterName:Array = new Array(tf0,tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8);

                 

                 

                 

                var i:uint = 0;
                var i2:uint = 0;

                 

                 

                 

                function changeColor(evt:Event):void
                {
                    if (i == colors.length)
                    {
                        i = 0;
                    }
                   
                    if (i2 == letterName.length)
                    {
                        i2 = 0;
                    }

                 

                    letterName[i2].textColor = colors[i];
                    i++;
                    i2++;
                    trace(i2);

                 


                }

                 

                stage.addEventListener(Event.ENTER_FRAME, changeColor);

                • 5. Re: I found this cute swf file
                  Ned Murphy Adobe Community Professional & MVP

                  Try something like...

                   

                  var colors:Array = new Array(0x000000,0xFF0000,0x00FF00,0x0000FF,0xFF00FF,0xFFFF00,0x00FFFF,0xFFFFFF,0xCCCCCC);
                  var letterName:Array = new Array(tf0,tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8);


                  var c:uint = 0;

                  function changeColor(evt:Event):void {
                      for(var i:uint=0; i<colors.length; i++){
                          letterName[i].textColor = colors[c];
                          c++;
                          if (c == colors.length){
                             c = 0;
                          }
                      }
                      c++; // start next round at the next color
                      if (c == colors.length){
                          c = 0;
                      }
                  }

                   

                  stage.addEventListener(Event.ENTER_FRAME, changeColor);

                  • 6. Re: I found this cute swf file
                    gross770 Level 1

                    where do youg get the various color names from?

                    new Array(0x000000,0xFF0000,0x00FF00,

                    • 7. Re: I found this cute swf file
                      gross770 Level 1

                      Dear Ned,

                      I slightly changed your suggested code to put in a letter counter so I can vary the number of letters from the number of colours you gave me.  Thanks again for your help.  The only thing I'd like to now is if there is some sort of table of colours I can refference to change or add colors in he colorsArray.

                       

                      thanks

                       

                      Aron

                       

                      var colors:Array = new Array(0x000000,0xFF0000,0x00FF00,0x0000FF,0xFF00FF,0xFFFF00,0x00FFFF,0xFFFFFF,0xCCCCCC);
                      var letterName:Array = new Array(tf0,tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10);

                       


                      var c:uint = 0;
                      var letterC:uint = 0;

                       

                      function changeColor(evt:Event):void
                      {
                          for (var i:uint=0; i<colors.length; i++)
                          {
                              letterName[letterC].textColor = colors[c];
                              c++;
                              letterC ++;
                              if (c == colors.length)
                              {
                                  c = 0;
                              }
                              if (letterC == letterName.length)
                              {
                                  letterC = 0;
                              }
                             
                          }
                          c++;// start next round at the next color
                          letterName[letterC].textColor = colors[c];
                          if (c == colors.length)
                          {
                              c = 0;
                          }
                      }

                       

                       

                       

                      stage.addEventListener(Event.ENTER_FRAME, changeColor);

                      • 8. Re: I found this cute swf file
                        Ned Murphy Adobe Community Professional & MVP

                        If you look at the color selector in Flash, when you select a color a hexidecimal color value is shown.  Just add "0x" infront of that and that's about it.  I just varied them without thought, but if you have specific colors you want to use, then use the color picker to determine what the codes are.

                        1 person found this helpful
                        • 9. Re: I found this cute swf file
                          gross770 Level 1

                          thanks again Ned

                           

                          regards,

                          Aron

                          • 10. Re: I found this cute swf file
                            Ned Murphy Adobe Community Professional & MVP

                            You're welcome Aron

                            • 11. Re: I found this cute swf file
                              gross770 Level 1

                              Hi again Ned,

                              I get the following error when I try to remove the event listener

                               

                              TypeError: Error #2007: Parameter listener must be non-null.
                                   at flash.events::EventDispatcher/removeEventListener()
                                   at samplepresentation_fla::MainTimeline/frame5()

                               

                              In frame one I have a line of code for my movie clip to blink that says in the MovieClip's time line :

                               

                              stage.addEventListener(Event.ENTER_FRAME, changeColor);

                              that was part of the code you gave me.

                               

                              then in frame 5 I have the following code :

                              Object(root).removeEventListener(Event.ENTER_FRAME, Object(root).changeColor);
                              trace("ENTER_FRAME removed");
                              stop();

                               

                              then I get theabove error.  How do I fix this one

                               

                              best regards,

                              Aron

                              • 12. Re: I found this cute swf file
                                Ned Murphy Adobe Community Professional & MVP

                                I'm not sure how/where frame 5 fits in, but you need to remove the listener you assigned....

                                 

                                If you use...

                                 

                                stage.addEventListener(Event.ENTER_FRAME, changeColor);

                                 

                                Then to remove it you use...

                                 

                                stage.removeEventListener(Event.ENTER_FRAME, changeColor);

                                 

                                If frame 5 is inside some movieclip, then you should have it call a function that lives on the main timeline that removes the event listener.  Or more properly, have it dispatch an event that gets listened for in the main timeline so the the removal can be done by an event handler there (see http://forums.adobe.com/thread/786778?tstart=0).

                                 

                                And if frame 5 is on the main timeline, and you are coming from an AS2 background where you made overuse of "_root" targeting (it happens to lots of folks), try to break the habit--it's just not needed.  It wasn't a good habit then and it isn't with AS3 either.

                                 

                                If you have new questions you should start new postings... postings with 0 replies draw attention.

                                • 13. Re: I found this cute swf file
                                  gross770 Level 1

                                  thanks for your help Ned.  The problem I'm having with doing a removeEventListener(Event.ENTER_FRAME, changeColor);

                                  is that I get an error of Access of undefined property  changeColor message.

                                   

                                  I am trying to remove an event listener that was set up in a movieClip and I'm not sure how to do this?

                                   

                                  best regards and thanks again for your help.

                                  Aron

                                  • 14. Re: I found this cute swf file
                                    gross770 Level 1

                                    one extra detail to the previous message.  I'm trying to remove the event listener in a movie clip while from code on the main time line

                                     

                                    best regards,

                                    Aron