我有一个叫做“currentMystery”的var我把这个问题简化为这两个函数 我相信。无论如何,第一次通过它工作并跟踪一个数组中的变量......但第二次通过某些东西将其更改为[Event type =“soundComplete”bubbles = false cancelable = false eventPhase = 2]
代码中有什么改变这个或我做错了什么? 非常感谢!
关于如何将其保持为与此处指定的相同var的任何想法:
currentMystery = "" + Mystries[4] + "";
...
public static var Mystries:Array = new Array("null","Joyful","Luminous","Sorrowful","Glorious");
public function checkDecade(e:Event = null)
{
if (decadeCount < 6)
{
Announce = true;
currentMystery = "" + Mystries[4] + "";
prayDecade(currentMystery);
}
}
public function prayDecade(currentMystery:String)
{
//// MY ISSUE IS WITH currentMystery. First time through
//// it works but the second through it is changing to
//// something like [Event type="soundComplete" bubbles=false etc...
trace("Pray Decade called: " +currentMystery);
if (Announce)
{
/// Sets PAUSE before Announc || Add features later to all prayers
setTimeout(function()
{
MainDoc.cPrayer.text = currentMystery;
trace("Called Announce"+decadeCount);
trace("Called Announce: Mystery: " + currentMystery+" Current Decade: " +decadeCount);
theAnnounce = new Sound();
theAnnounce.load(new URLRequest("audio/Rosary/Announce/"+currentMystery+"/"+decadeCount+".mp3"));
Praying = theAnnounce.play();
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
Announce = false;
}, 2000);
}
else
{
if (prayerCount==0)
{
trace("Our Father " + decadeCount);
//trace(love);
Begin = true;
/// Sets PAUSE before Our Father || Add features later to all prayers
setTimeout(function()
{
Begin = true;
ourFather();
}, 2000);
}
if (prayerCount >0 && prayerCount<11)
{
trace("Hail Mary " + prayerCount);
Begin = true;
hailMary();
}
if (prayerCount==11)
{
trace("Glory Be... " + prayerCount);
Begin = true;
gloryBe();
}
if (prayerCount==12)
{
trace("Oh My Jesus... " + prayerCount);
Begin = true;
ohMyJesus();
}
function ourFather(e:Event = null)
{
if (Begin)
{
Praying = OFB.play();
Praying.addEventListener(Event.SOUND_COMPLETE, ourFather );
}
else
{
Praying = OFE.play();
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
prayerCount++;
}
Begin = false;
}
function hailMary(e:Event = null)
{
if (Begin)
{
Praying = HMB.play();
Praying.addEventListener(Event.SOUND_COMPLETE, hailMary );
}
else
{
Praying = HME.play();
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
prayerCount++;
}
Begin = false;
}
function gloryBe(e:Event = null)
{
if (Begin)
{
Praying = GBB.play();
Praying.addEventListener(Event.SOUND_COMPLETE, gloryBe );
}
else
{
Praying = GBE.play();
Praying.addEventListener(Event.SOUND_COMPLETE, checkDecade );
prayerCount++;
}
Begin = false;
}
function ohMyJesus(e:Event = null)
{
Praying = OMJ.play();
Praying.addEventListener(Event.SOUND_COMPLETE, checkDecade );
prayerCount = 0;
decadeCount++;
}
}//End if Else
}
答案 0 :(得分:1)
代码中有什么改变这个或我做错了什么?
'SoundChannel'的事件处理程序错误。
Praying.addEventListener(Event.SOUND_COMPLETE, prayDecade );
在prayDecade
中,作为参数将传递event object(Event.SOUND_COMPLETE),而不是您正在等待的字符串。所以[Event type="soundComplete" bubbles=false cancelable=false eventPhase=2]
是事件的String表示。
答案 1 :(得分:1)
您正在使用prayDecade
方法作为声音完成事件的处理程序,并直接在您的代码中调用它。当它作为事件处理程序调用时,它接收的参数是一个事件对象,它被强制转换为string
并覆盖本地(prayDecade
函数)范围内的公共变量。
我认为如果您按如下方式更新函数,您将得到您期望的结果(假设currentMystery
是类范围中的公共变量:
public function prayDecade(e:Event)
{
trace("Pray Decade called: " + currentMystery);
// ....
}
当您直接调用该方法时,请不要传递变量:
// Assuming currentDecade is in scope in the prayDecade method
prayDecade(/*currentMystery*/);