25 Replies Latest reply on Apr 9, 2009 12:44 PM by kglad

    Making an aircraft instrument with moving text

    logeye
      f8as2_

      Greetings all,

      I'm trying to progress in my actionscript skills and use more actionscript. In the past I created a static movie clip maybe 50 pixels wide by several hundred pixels tall. Starting at the top of the strip the alitiudes were written next to a hash mark, a couple of carriage returns, a hash mark without any numbers, a couple of carriage returns and a hash mark, and the process repeated.

      This movie clip was placed behind a mask and moved with a 'mc._y=' command. As the numbers came past the edge of the mask only part of the numbers would show. Only two or three numbers would be visible at any give time. As these numbers moved it gave the impression that the altitude or airspeed was changing.

      So my question: How would be the most efficient way to create these numbers dynamically, and have them scroll
      and appear as if under the masks edge when appropriate?

      I'm spinning my wheels on how to start. Any ideas??

      Thanks for all of you on this site. I've learned a great deal from you all.
        • 1. Re: Making an aircraft instrument with moving text
          kglad Adobe Community Professional & MVP

          are you trying to create the mask and movieclip with numbers with code instead of using the authoring environment?

          • 2. Re: Making an aircraft instrument with moving text
            logeye Level 1

            Thanks for the reply kglad,

             

            I think the first way I would like to try is to create text fields dynamically and have them scroll under the mask.  Once the've gone past the mask they are removed on one side and a new one created on the other side of the mask for the new number to appear.  Only 5 numbers and 10 hash marks need to be displayed at any give time.  The altitudes go from 0 to 42,000 ft in 100 ft increments.  I'm trying to base my display off an altitude variable and then creating offsets from that altitude for the display.

             

            The second way is Im trying to create 5 dynamic text fields and scroll them.  Once one goes past the masked area on one side I move it to the other side.

             

            So far I'm not making any progress.

             

            If you have an idea as to the most efficient way to progress it would help tremendously.

             

            Thanks again for all you do for this site and for the kids.

            The fla attached is the old way I did it for the airspeed indicator.

            The jpg attached is a screen shot of the new way I need to do it.

             

            (something about a picture being worth more than words.)

            • 3. Re: Making an aircraft instrument with moving text
              logeye Level 1

              Sorry the fla did not go through the first time.  Here's a second try.

              • 4. Re: Making an aircraft instrument with moving text
                logeye Level 1

                It says there was an error with the message...

                 

                "It appears you're not allowed to view what you requested. You might contact your administrator if you think this is a mistake. "
                don't know what this message means.
                I changed the extension to .txt to see if that is part of the problem.  If you get it just change it back to .fla.  If it doesn't come up this time, I'' just wait.
                Thanks for your patience.
                • 5. Re: Making an aircraft instrument with moving text
                  kglad Adobe Community Professional & MVP

                  (i don't generally download fla files to repair unless i'm hired and i don't think this is that great a problem.)

                   

                  you can use textfields, but there's no reason to use more than one textfield and that will simplify your coding.

                   

                  just create your textfield, make it multiline, create a textformat that you assign to the textfield and assign a "leading" property that meets your needs and then assign the text which will look something like:

                   

                  altituteTF.text="-\n-\n-\n1000\n-\n-\n-2000\n-\n-\n-\3000....\n-\n-\n-\42000";  // you will, of course, not include ellipses in your code

                  • 6. Re: Making an aircraft instrument with moving text
                    logeye Level 1

                    Thanks kglad,

                     

                    This gives me a starting point.  Registration point is upper left of the text field.   I can do the offsets.  I'm working on the setMask which hasen't worked yet.

                     

                     

                    The fla attached was just an example of the way I used to move the text around.  I figured motion along with a pix would be more meaningful but you've got me started in the right direction.

                     

                    Thanks again.

                    • 7. Re: Making an aircraft instrument with moving text
                      kglad Adobe Community Professional & MVP

                      you'll need to embed your textfield's font and you'll need to make the textfield a child of a movieclip so you can use setMask on the parent movieclip.  (setMask() is a movieclip method, not a textfield method.)

                       

                      like so:

                       

                      this.createEmptyMovieClip("mc",1);

                      mc.createTextField(...)

                      • 8. Re: Making an aircraft instrument with moving text
                        logeye Level 1

                        Thank you kglad,

                         

                        I have the text created dynamically and it is working under the mask.  Yea!!!!   To fill in the textField more quickly, can you put (concantenate) a carriage return into the textField?  I would like to create the text content with a for next loop if possible.  Posts on the forum seem to indicate this may be a problem.

                         

                        Thank you very much!

                         

                         

                        • 9. Re: Making an aircraft instrument with moving text
                          kglad Adobe Community Professional & MVP

                          there should be no problem using a for-loop to populate your textfield:

                           

                          currentAltitude = 1000;

                          highlimitAltitude = 27000;

                          hashNumBetweenAltitudes = 3;

                           

                          for(var i=0;i<27000;i++){

                          if(i%(hashNumBetweenAltitudes+1) == 0){

                          tf.text = "-"+currentAltitude+"\n";

                          currentAltitude += 1000;

                          if(currentAltitude>highlimitAltitude){

                          break;

                          }

                          } else {

                          tf.text = "-\n";

                          }

                          }

                           

                          // and you might want to remove the last last after this loop exits.

                          • 10. Re: Making an aircraft instrument with moving text
                            logeye Level 1

                            Thanks again kglad,

                             

                            I'm learning a lot.  I've got everything working and it looks gooood.  Mmy concern is the swf file takes soooooo long to execute (about 10 seconds). I haven't even tried the airspeed tape yet.  Plus the altitude tape has sort of a magnifier window over the altitude tape (it behaves differently that the altitude tape).

                             

                            I had to make the altitude display in 200 ft increments which added to the delay.  The upperLimitAltitude and LowerLimitAltitudes help the load time a lot and I can work with this for most of our training.

                             

                            Thank you kglad for your time with me and with the others here on the site..

                             

                             

                            • 11. Re: Making an aircraft instrument with moving text
                              kglad Adobe Community Professional & MVP

                              you're welcome.

                               

                              that code should execute once only and will not have any perceptible impact on the host computer, even if it's an old one.

                              • 12. Re: Making an aircraft instrument with moving text
                                logeye Level 1

                                I've got to be doing something wrong here.

                                 

                                When the text field is auto filled with the for loop, I lose the text Formatting.  I can comment out the items inside the for loop and the formatting works fine (if I assign some text to the text field).  Once I allow the  'if (i%(hashNumBetweenAltitudes+1) == 0) {' statement, the textFormatting goes away????  It's probably my modifications.  The items in bold below are where I think I've messed up.

                                 

                                 

                                 

                                // Create Text Formatting
                                var altitude_fmt:TextFormat = new TextFormat();
                                altitude_fmt.font = "Arial-14Bold";
                                altitude_fmt.color = 0xFFFFFF;
                                // End Text Formatting
                                // Create the Movieclip - altitudeTape -  to hold the TextField
                                this.createEmptyMovieClip("altitudeTape", this.getNextHighestDepth());
                                // Create the textField  - altitudeTF - inside the movieclip
                                altitudeTape.createTextField("altitudeTF", 1, 600, 200, 60, 5000);
                                // assign attributes to the textField
                                with (altitudeTape) {
                                    //altitudeTF.text = "─\n─\n─\n─     42000";//
                                     altitudeTF.color = 0xFFFFFF;
                                     altitudeTF.multiline = true;
                                     altitudeTF.wordWrap = true;
                                     altitudeTF.type = "dynamic";
                                     altitudeTF.background = true;
                                     altitudeTF.backgroundColor = 0x4f494f;
                                     altitudeTF.html = false;
                                     altitudeTF.embedFonts = true;
                                     altitudeTF.selectable = false;
                                     altitudeTF.bold = true;
                                     altitudeTF.align = "left";
                                     altitudeTF.leftMargin = 0;
                                     altitudeTF.rightMargin = 0;
                                     altitudeTF.indent = 0;
                                     altitudeTF.leading = 0;
                                }
                                //
                                //
                                altitudeTape.altitudeTF.setTextFormat(altitude_fmt);
                                altitudeTape.setMask(dumbMask_mc);
                                // automate the textField content
                                currentAltitude = 42000;
                                highLimitAltitude = 42000;
                                if (currentAltitude>highLimitAltitude) {
                                     currentAltitude = highLimitAltitude;
                                }
                                if (currentAltitude<lowLimitAltitude) {
                                     currentAltitude = lowLimitAltitude;
                                }
                                lowLimitAtitude = 0;
                                hashNumBetweenAltitudes = 1;
                                for (var i = 420; i>0; i--) {
                                     if (i%(hashNumBetweenAltitudes+1) == 0) {
                                          altitudeTape.altitudeTF.text += "─     "+currentAltitude+"\n";
                                          currentAltitude -= 200;
                                          if (currentAltitude<lowLimitAltitude) {
                                               break;
                                          }
                                     } else {
                                      altitudeTape.altitudeTF.text += "\n\n-\n\n\n";
                                    }
                                }    

                                 

                                 

                                Thanks for your patience.

                                • 13. Re: Making an aircraft instrument with moving text
                                  kglad Adobe Community Professional & MVP

                                  i didn't check all your code, but you must have that font in your library and it must have linkage id = Arial-14Bold

                                   

                                  you also have a typo:  lowLimitAtitude = 0; that needs to be fixed.

                                  • 14. Re: Making an aircraft instrument with moving text
                                    logeye Level 1

                                    The setFormat works with embededFonts IF I hardwire the .text as you first suggested.  If I'm not misunderstanding this then I feel the embeded fonts work OK.  There is Arial-14Bold in the library, It is exported for actionscript in frame 1 and the instance name is Arial-14Bold. (Thanks, I did fix my typo.)

                                     

                                    Once I use the for loop, even if embeded=false, the setFormat does not to work anymore the text goes back to black unbolded.

                                     

                                    We sure close though.

                                     

                                     

                                    Thanks,

                                    • 15. Re: Making an aircraft instrument with moving text
                                      kglad Adobe Community Professional & MVP

                                      find your font in your library, right click on it and in the linkage id box copy and paste: Arial-14Bold.

                                      • 16. Re: Making an aircraft instrument with moving text
                                        logeye Level 1

                                        Thanks for the suggestion.  I copied from the identifier block and pasted it back into the same box, no luck.  I copied it from the action script panel to the Identifier Box, no luck.  I retyped it in, no luck.  I completely removed all info and saved it and then reapplied all the above with no luck.

                                         

                                        If I purposely disable the path to the altitudeText in the for look everything seems to work fine.

                                         

                                         

                                        with (altitudeTape) {
                                           altitudeTF.text = "─\n─\n─\n─     999";

                                        }

                                         

                                        for (var i = 420; i>0; i--) {
                                            trace(i);
                                            altitudeTF.text = "─\n─\n─\n─     42000";
                                            if (i%(hashNumBetweenAltitudes+1) == 0) {
                                                trace("if");
                                                altitudeTF.text = "─\n─\n─\n─     42000";
                                            } else {
                                                trace("else");
                                                altitudeTF.text = "─\n─\n─\n─     42000";
                                            }
                                        }

                                         

                                        The output is 999 and is correctly formatted which is what I would expect.  All the traces show OK. The path to the altitudeText is wrong in the for loop.

                                        If I take the same code and correctly assign the path to all the options in the for loop I get nothing in the output window and all the traces work OK..

                                         

                                         

                                        with (altitudeTape) {
                                           altitudeTF.text = "─\n─\n─\n─     999";

                                        }

                                         

                                        for (var i = 420; i>0; i--) {
                                            trace(i);
                                            altitudeTape.altitudeTF.text = "─\n─\n─\n─     42000";
                                            if (i%(hashNumBetweenAltitudes+1) == 0) {
                                                trace("if");
                                                altitudeTape.altitudeTF.text = "─\n─\n─\n─     42000";
                                            } else {
                                                trace("else");
                                                altitudeTape.altitudeTF.text = "─\n─\n─\n─     42000";
                                            }
                                        }

                                         

                                        The above gives no text at all.

                                         

                                        Perplexed, I am.

                                         

                                         

                                        • 17. Re: Making an aircraft instrument with moving text
                                          kglad Adobe Community Professional & MVP

                                          you should be using setNewTextFormat(), not setTextFormat().

                                          • 18. Re: Making an aircraft instrument with moving text
                                            logeye Level 1

                                            Thank you kglad for you patience.  That did it.

                                             

                                            It reminds me of when I spent two hours trting to get dynamic text to work only to find out I had been successfulle creating white text on a white background.

                                             

                                            You have a teachers heart.

                                             

                                             

                                            • 19. Re: Making an aircraft instrument with moving text
                                              kglad Adobe Community Professional & MVP

                                              you're welcome.

                                               

                                              please mark this thread as answered and if there was a particular answer or answers that helped with the original question, mark those.  it will help people the search the forums or google similar problems.

                                              • 20. Re: Making an aircraft instrument with moving text
                                                kglad Adobe Community Professional & MVP

                                                (and i've spent more than a few hours debugging text that's the same color as its background.)

                                                • 21. Re: Making an aircraft instrument with moving text
                                                  logeye Level 1

                                                  Showing my ignorance again.  I can't find a way to mark the solution.

                                                  • 22. Re: Making an aircraft instrument with moving text
                                                    kglad Adobe Community Professional & MVP

                                                    don't worry about it.  (i don't know where it is either.  i'm just figuring out how to bend this new forum to allow me to do the simplest things.)

                                                    • 23. Re: Making an aircraft instrument with moving text
                                                      kglad Adobe Community Professional & MVP

                                                      i made a test thread and when i went to reply to the test message, there was an option at the top to mark the thread as answered.  i didn't see a way to mark a particular answer though so i'm clearly not an expert in the way these forums work (or should work).

                                                      • 24. Re: Making an aircraft instrument with moving text
                                                        logeye Level 1

                                                        It's wierd.  If you search on "

                                                        basic Flash preferences question

                                                         

                                                        the response to my post of 6 days ago,  it has two buttons to mark 1) the correct answer ort 2)if the answer was helpful. I can't find them in response to my other posts.

                                                        • 25. Re: Making an aircraft instrument with moving text
                                                          kglad Adobe Community Professional & MVP

                                                          let's just let this thread drift down the list.  it's not that important to mark it answered.