A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Text fading in/out in the textbox

  1. #1
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332

    Text fading in/out in the textbox

    Hi there!

    I need to do the following thing: have a few words or phrases which fade in and out, once one word faded out - the other one fades in, stays visible for a few seconds and then fades out and so on. Obviously it can be done by animation, but I have to do it by code.
    Is it possible to do it? And if it is - how???

    Thanks in advance!!!

    Sometimes the most simple things are the most effective...

  2. #2
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Code:
    function fadeIn() {
    	myText._alpha += 2;
    	if (myText._alpha>=100) {
    		this.onEnterFrame = fadeOut;
    	}
    }
    function fadeOut() {
    	myText._alpha -= 2;
    	if (myText._alpha<=0) {
    		this.onEnterFrame = null;
    		nextText();
    	}
    }
    function nextText() {
    	myText.text = " bla bla ";
    	myText._alpha = 0;
    	this.onEnterFrame = fadeIn;
    }
    nextText();
    And make sure your Font is embedded in that textfields, as not
    embedded Fonts won't render _alpha.
    }

  3. #3
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332
    Thank you very much!!!

    Another question: where do I enter the next word, so after that "bla bla" will appear, lets say, "yada yada", and after "yada yada" - "na na na" and so on?

    Sometimes the most simple things are the most effective...

  4. #4
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    This time i give a tip only.. no full code:

    var counter:Number=0;
    var textArray:Array= new Array("yabba yabba", "tuppidippi", "pfudiwud");

    you will need as well: textArray.length and counter++
    and of course textArray[counter]


    (if you need a " in your text put \"
    a linebreak would be \n and a Tab \t)

  5. #5
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332
    Sorry, I tried to figure it out but nothing seems to work... I have no idea how to use it (not to mention that I never even knew that there's a "length" attribute exists, so I have no idea how it works)...

    What can I do, I'm more of a designer than a programmer...

    Sometimes the most simple things are the most effective...

  6. #6
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    *sigh* designers...
    Code:
    var counter:Number = 0;
    var textArr:Array = new Array("Text1", "Text2", "Text3");
    function nextText() {
    	myText.text = textArr[counter];
    	counter++;
    	if (counter>=textArr.length) {
    		counter = 0;
    	}
    	myText._alpha = 0;
    	this.onEnterFrame = fadeIn;
    }

  7. #7
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332
    Quote Originally Posted by McUsher
    *sigh* designers...
    Yeah, I know...



    Anyway, I still have a little problem... I now have this code:

    Code:
    function fadeIn() {
    	myText._alpha += 2;
    	if (myText._alpha>=100) {
    		this.onEnterFrame = fadeOut;
    	}
    }
    function fadeOut() {
    	myText._alpha -= 2;
    	if (myText._alpha<=0) {
    		this.onEnterFrame = null;
    		nextText();
    	}
    }
    var counter:Number = 0;
    var textArr:Array = new Array("Text1", "Text2", "Text3");
    function nextText() {
    	myText.text = textArr[counter];
    	counter++;
    	if (counter>=textArr.length) {
    		counter = 0;
    	}
    	myText._alpha = 0;
    	this.onEnterFrame = fadeIn;
    }
    nextText();
    but now it doesn't work... I don't see any text at all now... I tried here a few combinations (well, every possible combination I could've think of), but it still didn't work. What seems to be the problem now?

    Again, thank you very much for your help?

    Sometimes the most simple things are the most effective...

  8. #8
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Oh, are you probably exporting to AS1.0? try changing to AS2.0

    I assume the Font still beeing embedded.

  9. #9
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332
    ahm... I'm using Flash MX (not MX 2004), it doesn't have AS2...

    and yes, the font is still embedded.

    Sometimes the most simple things are the most effective...

  10. #10
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hmm with FlashMX2004 i can export to FlashPlayer 6 with AS2.0 ?! strange..

    anyways just change:
    var counter:Number = 0;
    var textArr:Array = new Array("Text1", "Text2", "Text3");

    to
    var counter= 0;
    var textArr= new Array("Text1", "Text2", "Text3");

    As AS1 doesn't know about Types..

  11. #11
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332
    I don't know about Types neither, but this change worked! Now everything works like a charm!!!

    Many, many thanks for your help!!! I really appreciate it! Thank you!


    P.S. Lots of exclamation marks, he?

    Sometimes the most simple things are the most effective...

  12. #12
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hehe, with AS2.0 you can define like

    var counter:Number = 0;

    Now flash knows, that counter is a Number.
    If you try to do:
    counter = "myString";
    the compiler would tell you, that u have an error.

    For freshmeat it might be more confusing, but after u got used
    to it, it is a nice and tidy way to easier find your mistakes.

    Have fun with your work

  13. #13
    Senior Member Ingale's Avatar
    Join Date
    Jun 2003
    Posts
    332
    Thanks, I'll try...
    Guess I'll have more questions on the road (I haven't been dealing with Flash for 2 years, and already forgot that little I knew)...

    I have another work after I'm done with this one, and maybe after those two I'll find some time to learn that AS thing... Or AS2... Which one is the easiest?

    Sometimes the most simple things are the most effective...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center