Hello! Complete actionscript/flash newb here. I’ll try to explain my problem as clearly as I can… My brain is fried after much googling, random guessing, and frustration. :insomniac: any help or pointers would be hugely appreciated.
I’m creating a flash animation using Todd Perkins’s “Displaying Synched Song Lyrics Tutorial” . I have the initial flash working okay. However, I would like to add a fade in transition for each song lyric. My newbiness kicks in as I have no idea how to create what I want to happen.
I think I need to be doing some kind of “addChild” doobedad, and then manipulate the child element with a tween… (that bright idea came from this tutorial). I’ve been operating under the assumption that I need to add the tween information to the updateLyrics function… but I either get compile errors of various sorts, or the swf compiles okay and no transitions happen.
Here’s the actionscript I’m using at the moment:
import flash.display.Stage;
import flash.events.*;
import flash.text.*;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var lyrics:XML;
var loader:URLLoader = new URLLoader();
var lyricFade:Sprite = new Sprite();
var lyricFading:Sprite = new Sprite();
var startTime:uint = 0;
var currentTime:uint = 0;
var currentLyric:uint = 0;
var moby:Sound = new Sound();
var mobyChannel:SoundChannel;
moby.addEventListener(Event.COMPLETE, soundLoaded);
moby.load(new URLRequest("gamma.mp3"));
function soundLoaded(event:Event):void
{
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(new URLRequest("lyrics.xml"));
}
function xmlLoaded(event:Event):void
{
lyrics_txt.text = "Lyrics have loaded, please click play.";
lyrics = new XML(loader.data);
play_btn.addEventListener(MouseEvent.CLICK, playSong);
}
function playSong(event:MouseEvent):void
{
startTime = getTimer();
currentLyric = 0;
lyrics_txt.text = "";
if(mobyChannel)
{
mobyChannel.stop();
}
mobyChannel = moby.play(0);
addEventListener(Event.ENTER_FRAME, updateLyrics);
}
function updateLyrics(event:Event):void
{
addChild(lyricFade);
lyricFade.addChild(lyricFading);
new Tween(lyricFading,"alpha",Strong.easeIn,0,1,1,true);
currentTime = getTimer() - startTime;
if(currentTime >= lyrics.lyric[currentLyric].@time)
{
lyrics_txt.text = lyrics.lyric[currentLyric];
currentLyric ++;
if(currentLyric >= lyrics.lyric.length())
{
removeEventListener(Event.ENTER_FRAME, updateLyrics);
}
}
}
here’s a quick example of what the XML file is supposed to look like:
<lyrics>
<lyric time="400">Row, row, row your boat</lyric>
<lyric time="560">gently down the stream!</lyric>
<lyric time="780">Merrily, merrily, merrily</lyric>
<lyric time="832">life is but a dream!</lyric>
</lyrics>
please help!!! even if it’s to hit me with a newbhammer and point out what I’m doing horribly wrong. thank you!!