PDA

View Full Version : Better than ENTER_FRAME for this project?



tpann
July 23rd, 2008, 05:07 PM
I'm not a developer and over the course of the past year during which I've learned a lot of AS3, I have probably not come close to applying what would be considered "best practices." I have lots of code that could probably be dramatically changed to improve performance.

Here's a bit of my code that I'd like advice about. Is there a different technique I can use to do the following, that's more streamlined?

masterCounter is variable that's iterated every tenth of a second on the root timeline. The following code is in a movie clip that's been added to the stage:



addEventListener(Event.ENTER_FRAME, s003Listener);
function s003Listener(event:Event):void {
if (!event.target.parent.masterIsPlaying) {
pauseAudio();
}
if (event.target.parent.masterIsPlaying) {
resumeAudio();
}
if (event.target.parent.masterCounter == 1) {
startAudioBkgd();
}
if (event.target.parent.masterCounter == 10) {
startAudio01();
}
if (event.target.parent.masterCounter == 50) {
Tweener.addTween(s003Presented, {alpha:1, time:fade});
}
if (event.target.parent.masterCounter == 62) {
playWhoosh();
}
if (event.target.parent.masterCounter == 65) {
s003Presented.gotoAndPlay(2);
}
if (event.target.parent.masterCounter == 95) {
Tweener.addTween(s003Presented, {alpha:0, time:fade});
Tweener.addTween(s003title, {alpha:0, time:fade});
}
// ...etc. Imagine there are a hundred of these if statements...


Don't flame me for being a Flash Butcher!

Thanks for any help!

bonnieraymond
July 24th, 2008, 12:32 AM
you are doing WRONG. Think again!

TheCanadian
July 24th, 2008, 12:41 AM
You could use a switch statement; check the help files/livedocs.

amarghosh
July 24th, 2008, 06:46 AM
addEventListener(Event.ENTER_FRAME, s003Listener);
function s003Listener(event:Event):void
{
if (!event.target.parent.masterIsPlaying)
pauseAudio();
else
resumeAudio();
switch(event.target.parent.masterCounter)
{
case 1:
startAudioBkgd();
break;
case 10:
startAudio01();
break;
//etc.. don't forget to break after each case
}
}