FORUMS: list search recent posts

Dynamic Text Problem

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kathy Summers
Dynamic Text Problem
on Jun 8, 2010 at 3:58:24 pm

I am having a problem with the dynamic text on a site I am designing.

I am not a proficient Action Script coder, so this may be a simple solution.

The text is meant to look as though it is typewritten, with each letter appearing separately. This part works fine. The text box should then disappear, however, and I can't get that to work. Any ideas on how to do this? I tried using motion tweens and adjusting the alpha via the timeline, but I had horrible results and all I had was flickering text. I think I just need a little bit more Action Script code.

I am using AS3.

Here is the code:

var str:String = '"jennifer brings exactly the kind of personal warmth and professionalism that is ideal for that special day." -cynthia bartley, mother of the bride';

var i:uint = 0;

var timer:Timer = new Timer(40);

timer.start();

timer.addEventListener(TimerEvent.TIMER,gotime);

function gotime(e:TimerEvent) {

textbox_txt.appendText(str.charAt(i));
i++;
if(i>=str.length) {
timer.stop()

}

}


Any help is greatly appreciated. Thanks.

Kathy


Return to posts index

demetri tashie
Re: Dynamic Text Problem
on Jun 8, 2010 at 4:06:49 pm

when do you want it to disappear? right after it is finished writing?

if so, then just add this one line of code to the "if" statement:

if(i>=str.length) {
timer.stop();
textbox_txt.visible=false; // add this to make it disappear

}



Return to posts index

Kathy Summers
Re: Dynamic Text Problem
on Jun 8, 2010 at 4:28:18 pm

Thank you Demetri.

That works, but the last word disappears too fast. Is there a way to make it hold for a second or two longer?

Kathy

Kathy


Return to posts index


Kathy Summers
Re: Dynamic Text Problem
on Jun 8, 2010 at 4:49:09 pm

I just figured out how to make it last longer. My client wants another text box to show up to the left of the one I've been working on, using the same typewriter effect. Is there an easy way to make that happen?

Thanks!

Kathy

Kathy


Return to posts index

demetri tashie
Re: Dynamic Text Problem
on Jun 8, 2010 at 7:03:44 pm

just keep on adding to the code in a modular fashion.
add a second textbox2_text where you want it.

look at this code for how it all works together. adjust it as necessary
var str:String = '"jennifer brings exactly the kind of personal warmth and professionalism that is ideal for that special day." -cynthia bartley, mother of the bride';
var str2:String = 'this is the secons string asdasdasdasdasdadadasdasdas';

var i:uint = 0;
var j:uint=0;

var timer:Timer = new Timer(40);
var timer2:Timer = new Timer(40);

timer.start();

timer.addEventListener(TimerEvent.TIMER,gotime);


function gotime(e:TimerEvent) {

textbox_txt.appendText(str.charAt(i));
i++;
if(i>=str.length) {
timer.stop();
textbox_txt.visible=false;
timer2.start();
timer2.addEventListener(TimerEvent.TIMER,gotime2);

}

}

function gotime2(e:TimerEvent) {

textbox2_txt.appendText(str2.charAt(j));
j++;
if(j>=str2.length) {
timer2.stop();
textbox2_txt.visible=false;

}

}



Return to posts index

Kathy Summers
Re: Dynamic Text Problem
on Jun 9, 2010 at 4:49:25 pm

That works perfectly. Thank you Demetri.

Kathy


Return to posts index


Kathy Summers
Re: Dynamic Text Problem
on Jun 10, 2010 at 4:26:49 pm

What's the best way to make all the text strings loop once it gets to the last one? I know I could do it for one, but not sure how to do it for all of them.

Thanks again.



Kathy


Return to posts index

demetri tashie
Re: Dynamic Text Problem
on Jun 10, 2010 at 8:08:22 pm

i am not at my computer with Flash , so i can't test this, but this should work to keep both of them looping:
var str:String = '"jennifer brings exactly the kind of personal warmth and professionalism that is ideal for that special day." -cynthia bartley, mother of the bride';
var str2:String = 'this is the secons string asdasda sdasd asdadad asdasdas';

var i:uint = 0;
var j:uint=0;

var timer:Timer = new Timer(40);
var timer2:Timer = new Timer(40);

timer.start();


timer.addEventListener(TimerEvent.TIMER,gotime);


function gotime(e:TimerEvent) {

textbox_txt.appendText(str.charAt(i));
textbox2_txt.text="";
textbox2_txt.visible=true;
i++;
if(i>=str.length) {
timer.stop();
timer.removeEventListener(TimerEvent.TIMER,gotime);
j=0;
textbox_txt.visible=false;
timer2.start();
timer2.addEventListener(TimerEvent.TIMER,gotime2);

}

}

function gotime2(e:TimerEvent) {

textbox2_txt.appendText(str2.charAt(j));
j++;
if(j>=str2.length) {
timer2.stop();
timer2.removeEventListener(TimerEvent.TIMER,gotime2);
textbox2_txt.visible=false;
i=0;
textbox_txt.text="";
timer.start();
timer.addEventListener(TimerEvent.TIMER,gotime);
textbox_txt.visible=true;

}

}


i also saw in the previous code that we did not remove the event listeners for the timer(s) once they were done and no longer needed. you should always remove them, as they would still be drawing processing power.


Return to posts index

Kathy Summers
Re: Dynamic Text Problem
on Jun 18, 2010 at 3:42:18 am

Perfect. Thanks!

Kathy


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]