Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-16-2012, 10:39 PM   #1
CutieDie
Registered User
 
Join Date: May 2011
Posts: 13
Default Repeating output

I have a bit of code thatis supposed to increment through an xml file once it detects the correct input, but it keeps repeating the output(audio) once it increments to the next item in the file. I need to know why its happening and how to stop this. Someone help me please.
CutieDie is offline   Reply With Quote
Old 05-16-2012, 10:43 PM   #2
CutieDie
Registered User
 
Join Date: May 2011
Posts: 13
Default

Here is the code


//Necessary Imports and variable definitons
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.media.SoundMixer;
import flash.utils.*;

var delayStart
var wordXML:XML;
var effectsXML:XML;
var url;
var audioUrl;
var audioTest:Boolean;
var comment:String;//stores the current word being displayed
var ccounter:int;//stores the value current word being displayed
var counter1:int;//stores the number of words in the file at level 1
var counter2:int;//stores the number of words in the file at level 2
var i:int;
var a:int;
var depth:int;//stores the length of the word XML file
var wordAudio:Sound;
var wordChannel:SoundChannel;
wordAudio = new Sound();
wordAudio.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

//Code to load XML file that contains the sound effects for the game
var effectsLoader:URLLoader = new URLLoader();
effectsLoader.load(new URLRequest("Effects.xml"));
effectsLoader.addEventListener(Event.COMPLETE, processEffectsXML);

function processEffectsXML(e:Event):void
{
effectsXML = new XML(e.target.data);
effectsXML.ignoreWhite=true;
}

//Code to load XML file that contains data on the words for the game
var wordLoader:URLLoader = new URLLoader();
wordLoader.load(new URLRequest("WordList.xml"));
wordLoader.addEventListener(Event.COMPLETE, processWordXML);

//Function to handle errors
function ioErrorHandler(error:IOErrorEvent):void
{
trace("Error handler",error.text);
}

//Function to process the word XML file
function processWordXML(e:Event):void
{
wordXML = new XML(e.target.data);
wordXML.ignoreWhite=true;
//trace(wordXML);
depth = wordXML.child("*").length();
//trace(depth);
for (a = 0; a < depth; a++)
{
if(wordXML.*.Level[a] == 1)
{
counter1 ++;
//trace(counter1);
}

}
Word.text = wordXML.*.Name[i]
delayStart = setInterval(startCode,700);
function startCode():void
{
audioUrl = wordXML.*.Audio[i];
playAudio(audioUrl);
clearInterval(delayStart);
}
}

//Function to play audio
function playAudio(audioUrl):void
{
var wordAudio:Sound;
var wordChannel:SoundChannel;
wordAudio = new Sound();
wordAudio.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
wordAudio.load(new URLRequest(audioUrl));
wordChannel = wordAudio.play();
}

//Code to play the word audio
Replay.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);

function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent) :void
{
audioUrl = wordXML.*.Audio[i];
playAudio(audioUrl);
}

//Code to delay playing of audio
function startCode():void
{
if (!ccounter == i)
{
playAudio(audioUrl);
clearInterval(delayStart);
}
}

//Function to determine if the answer is correct
function verify(answer):String
{
if (answer == wordXML.*.Syllables[i])
{
url = effectsXML.*.url[0];
//trace("correct");
i++;
ccounter ++;
Word.text = wordXML.*.Name[i];
}
else
{
url = effectsXML.*.url[1];
//trace("Incorrect");
}
if (i == counter1)
{
url = effectsXML.*.url[3];
gotoAndPlay(1);
}
return url;
}

//Code to detect answer input by user

var answer:int;
//Code for the first button
Answer1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
answer = 1;
verify(answer);
//trace("mouse click");
playAudio(url);
delayStart = setInterval(startCode2,2000);

function startCode2():void
{
trace(ccounter);
trace(i);
if (!ccounter == i)
{
audioUrl = wordXML.*.Audio[i];
playAudio(audioUrl);
clearInterval(delayStart);
}
audioUrl = wordXML.*.Audio[i];
playAudio(audioUrl);
}

}

//Code for the second button
Answer2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
answer = 2;
//trace("Mouse clicked");
verify(answer);
playAudio(url);
delayStart = setInterval(startCode,2000);
}

//Code for the third button
Answer3.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);

function fl_MouseClickHandler_4(event:MouseEvent):void
{
answer = 3;
//trace("Mouse clicked");
verify(answer);
playAudio(url);
delayStart = setInterval(startCode,2000);
}

//Code for the fourth button
Answer4.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_5);

function fl_MouseClickHandler_5(event:MouseEvent):void
{
answer = 4;
//trace("Mouse clicked");
verify(answer);
playAudio(url);
delayStart = setInterval(startCode,2000);
}

//Code for the fifth button
Answer5.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_6);

function fl_MouseClickHandler_6(event:MouseEvent):void
{
answer = 5;
//trace("Mouse clicked");
verify(answer);
playAudio(url);
delayStart = setInterval(startCode,2000);
}

//Code to return to the main menu
Back.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_6);

function fl_ClickToGoToAndPlayFromFrame_6(event:MouseEvent) :void
{
i = 0;
ccounter = 0;
gotoAndPlay(1);
}
CutieDie is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:40 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.