Typewriter text problem

Another hour, another thread, heh heh . . . . heh

Heh?

Well, I am using the following typewriter text effect on the first frame of my main timeline:
[AS]
myText = “”; // text box is empty to start
this.onEnterFrame = function() {
MCtxt.text = myText.substr(0, type); // set the length of the string to the length of the type
type += 1; // keep increasing type until all of text is printed
var c = (myText.length-MCtxt.text.length); // create variable c to decrease as string is output
myText = “blah blah blah, yadda yadda yadda.”;
if (c == 1) {
_root.movie_close.gotoAndPlay(2); // when all of text is out play animation
}
};
[/AS]

I set the variable c to count down to the end of the effect so when it “prints” the last letter it triggers an animation of an arrow moving across the stage. The arrow animated movie clip is 240 frames long. When it gets to frame 120 I want it to stop which it does. Then I want to clear the text box and “print” something different. I want to use the same effect as above - when it gets to the last letter it goes to frame 121 and continues with the rest of the animation.

So on frame 120 I have this:
[AS]
stop();
thisText = “”; // text box is empty to start
this.onEnterFrame = function() {
_root.MCtxt.text = thisText.substr(0, type2); // set the length of the string to the length of the type
type2 += 1; // keep increasing type until all of text is printed
var d = (thisText.length-_root.MCtxt.text.length); // create variable c to decrease as string is output
thisText = “more text blah blah blah.”;
trace(d)
if (d == 1) {
gotoAndPlay(121); // when all of text is out play animation
}
}; }
[/AS]
The trace returns the correct number and when it reaches 0 it triggers the next phase of animation, but the text does not “print.” If I add _root to “thisText” then it does print but it prints all at once instead of doing the typewriter effect. What am I doing wrong?

http://proto.layer51.com/d.aspx?f=493

You know the funny thing is is that every time I’ve gone to that site (seen it many times in the past) the text is so small I can’t read it. When I maximize my window the font size doesn’t change. Is there a way to load the page so that one can actually see the text written there?

:bu:

if you have a scroller on your mouse. Hold down the Ctrl key and scroll up.

they’re is also the window’s accessibility tools (magnifying glass) :beam:

Duh, sheesh, thanks. :sigh:

So the prototype goes on the main timeline, obviously. And the “usage” goes wherever you want, like in my case on that frame in between two tweens on the movie clip (confidence grows shaky). And the “test” part goes . . . also on the main timeline? (confidence falls apart, tears fast approaching).

And how can I stick in my trigger variable © ?

you don’t HAVE to draw a text field using AS you could just draw one manually and give it a instance name. So you can place the prototype ANYWHERE and use it anywhere without any special paths.

if (i>str.length) {
			clearInterval(itv);
_root.movie_close.gotoAndPlay(2);

		}

Thanks Norie. Sorry to keep bothering you but I’m new to protoTypes (though I think they are excellent). Your code worked great but now it just keeps triggering the gotoAndPlay(2) over and over.

i would like to have it so that when the animation is triggered it goes to frame 120 where it stops and a new string is set to the Prototype (that works just fine). When that text is done it triggers the gotoAndPlay(121). And so on. There are a few more strings and animations to call including triggering animation on other movie clips. So where do I put that if statement and how do I change it with different strings? :h:

Sorry to ask dumb questions! :x


c = false;
TextField.prototype.typeWriter = function(str, ms) {
	var me = this;
	var i = 0;
	var itv = setInterval(function () {
		me.text = str.substring(0, i);
		i++;		
		if (i>str.length) {
			clearInterval(itv);
if(!c){
gotoAndPlay(2);
c = true;
}
		}
		updateAfterEvent();
	}, ms);
};

Brilliant. Thanks Norie. Once again I owe you . . .

If you are ever plan to be up north let me know and I’ll buy you a beer! :beer:

On the other hand - I offered that to Voetsjoeba once and he wasn’t even old enough to drink! Dang flash genius youngsters! (grumble grumble). :wink: