all groups > flash actionscript > june 2005 >
You're in the

flash actionscript

group:

Fade Clip In/Out over time


Fade Clip In/Out over time redl3tt3r
6/16/2005 8:28:47 PM
flash actionscript:
+ - The Problem - +
I have created a simple movie that loads a line of text from and external xml
file. Featuring next and previous buttons to cycle threw the various lines of
text in the xml file.

This in it self works swimmingly. But I hit a wall when I wanted to add a
little extra functionality to the movie. When you click next or previous I want
the text to: fade out > swap the text > fade in

I set my movie up the best I know how to do this, and I get no actionscript
errors when I preview the movie.

Here is a little about what the movie DOES do:
- When you preview the movie the text loads into the box.
- When you click next/previous it waits about a second and swaps out the text,
no fadeing.

I have attached my actionscript, if someone could find an error or offer a
better solution I would much appreciate the help.

Thanks in advance,
+ - redLetter - +


p = 0;
f = 0;
beniClip._alpha = 0;

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
description[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
}
firstBeni();
} else {
content = "file not loaded!";
}
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("beni1.xml");
/////////////////////////////////////

this.onEnterFrame = function() {
if (f == 0) {
Stop();
}

if (f == 1) {
if (beniClip._alpha>1) {
beniClip._alpha -= 10;
} else {
nextBeni();
}
}

if (f == 2) {
if (beniClip._alpha>1) {
beniClip._alpha -= 10;
} else {
prevBeni();
}
}

if (f == 3) {
if (beniClip._alpha<100) {
beniClip._alpha += 10;
} else {
f = 0;
}
}

}

previous_btn.onRelease = function() {
f = 2;
}

next_btn.onRelease = function() {
f = 1;
}

function nextBeni() {
if (p<(total-1)) {
p++;
beniClip.beni_txt.text = description[p];
f = 3;
}
}

function prevBeni() {
if (p>0) {
p--;
beniClip.beni_txt.text = description[p];
f = 3;
}
}

function firstBeni() {
beniClip.beni_txt.text = description[0];
f = 3;
}
Re: Fade Clip In/Out over time mandingo
6/17/2005 12:17:32 AM
Okay, this solution requires a little preparation...

Embed a font - I called mine "stdFont".

create a dynamic textField instance - I called mine "myText" (creative I know).

convert that textField to a movieSymbol - I called mine "myFaderText".

open the new movieSymbol and set up the font and format and embed the font for
the text field:

this.myFmt = new TextFormat();
this.myFmt.font = "stdFont";
this.myFmt.color = 0xFF0000;
this.myText.embedFonts = true;
this.myText.setTextFormat(this.myFmt);
this.myText.setNewTextFormat(this.myFmt);

go back to the main timeline and create the actions for your fader...

this.myFaderText.myText.text = "Some text is in here";
this.myFaderText.onFadeOut = function(clip){
clip._alpha -=10;
if(clip._alpha <=0){
clip._alpha =0;
clearInterval(clip.fadeOut);
clip.setNewText();
}
}
this.myFaderText.onFadeIn = function(clip){
clip._alpha +=10;
if(clip._alpha >=100){
clip._alpha = 100;
clearInterval(clip.fadeIn);
}
}
this.myFaderText.setNewText = function(){
this.myText.text = "You can pass in the new value";
this.fadeIn = setInterval(this.onFadeIn,100,this);
}
this.myFaderText.fadeOut =
setInterval(this.myFaderText.onFadeOut,100,this.myFaderText);

if you run that code, you should see it fade out... change text and fade back
in...

hope that helps,
cheers,
AddThis Social Bookmark Button