Skip navigation
Clockwise Gear
Currently Being Moderated

Need help creating a cursor effect.

Dec 30, 2012 11:47 AM

Tags: #action_script_3 #flash_cs5.5

I'm working on a little project that's like a text-based adventure, but played on a tumblr, so the readers submit their siggestions for actions.

I'm looking to create animations for each post, so that it looks like the reader is typing in the text on the "game."

I have the text-generation effect down using this code:

 

var myString:String = "text data goes here.";

var myArray:Array = myString.split("");

addEventListener(Event.ENTER_FRAME, frameLooper);

function frameLooper(event:Event):void

{

          if(myArray.length > 0)

                    {

                    tf.appendText(myArray.shift());

                    }

          else

                    {

                    removeEventListener(Event.ENTER_FRAME, frameLooper);

                    }

}

 

 

//code sporked from Adam Khoury's Flash Typing Text Effect Tutorial video

 

So that runs okay, but after that is done, I want there to be a final > prompt followed by a flashing cursor,as if asking for input.

If anyone has a suggestion, that would be much appreciated.

Thanks in advance!

 
Replies
  • Currently Being Moderated
    Dec 30, 2012 1:00 PM   in reply to Clockwise Gear

    In the section where you remove the event listeners you can append the ">" prompt...

     

                        }

              else

                        {

                        removeEventListener(Event.ENTER_FRAME, frameLooper);

                       

                         tf.appendText( ">" ); 

                        }

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 31, 2012 5:15 AM   in reply to Clockwise Gear

    Having the blinking cursor is possible, but is also often a bit of a hair puller to do so with AS3 code.  For myself, it seldom works, while others have no problem.  Here is the solution most commonly offered (relative to what you are doing)...

     

         removeEventListener(Event.ENTER_FRAME, frameLooper);

         tf.appendText(">");

         stage.focus = tf;

         tf.setSelection(tf.text.length,tf.text.length);

     

    You should find that if you don't see the cursor, if you start typoing it will begin filling in after the ">".  You might try testing in the final intended interface (browser, etc) instead of just the player in Flash... sometimes it works in one but not the other.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 31, 2012 1:22 PM   in reply to Clockwise Gear

    Your earlier explanation made more sense.  I cannot tell what you are trying to explain or point out in the last posting.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 1, 2013 11:42 AM   in reply to Clockwise Gear

    There's not much need to show anymore.  I already provided the code you can try to get a blinking cursor, but also said how it is iffy as far as it actually working. 

     

    The only difference I would offer for the code I provided earlier based on the image you show would be to add a new line before the ">", as in...

     

     

     

         removeEventListener(Event.ENTER_FRAME, frameLooper);

         tf.appendText("\n>");

         stage.focus = tf;

         tf.setSelection(tf.text.length,tf.text.length);  // in an ideal world this line, in league with the focus line preceding it will add the cursor... it just doesn't always work as advertised... especially for me

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 2, 2013 1:19 PM   in reply to Clockwise Gear

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points