-
Senior Member
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...
-
Flash Gordon
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.
}
-
Senior Member
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...
-
Flash Gordon
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)
-
Senior Member
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...
-
Flash Gordon
*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;
}
-
Senior Member
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...
-
Flash Gordon
Oh, are you probably exporting to AS1.0? try changing to AS2.0
I assume the Font still beeing embedded.
-
Senior Member
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...
-
Flash Gordon
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..
-
Senior Member
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...
-
Flash Gordon
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
-
Senior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|