var playGraph = new Chart();
var playPart1 = new Part1();
var playPart2 = new Part2();
var playPart3 = new Part3();
addChild(playGraph);
playGraph.gotoAndPlay(1);
var s1:SoundOne = new SoundOne();
s1.play();
playGraph.addEventListener(Event.COMPLETE, onCompleteGraph);
playPart1.addEventListener(Event.COMPLETE, onCompletePart1);
playPart2.addEventListener(Event.COMPLETE, onCompletePart2);
function onCompleteGraph(evt:Event):void
{
playPart1.x = 370;
playPart1.y = 190;
addChild(playPart1);
playPart1.gotoAndPlay(1);
}
function onCompletePart1(evt:Event):void
{
playPart2.x = 100;
playPart2.y = 100;
addChild(playPart2);
playPart2.gotoAndPlay(1);
var s2:Sound2 = new Sound2();
s2.play();
}
function onCompletePart2(evt:Event):void
{
removeChild(playPart2);
addChild(playPart3);
playPart3.gotoAndPlay(1);
var s3:Sound3 = new Sound3();
s3.play();
}
我的问题是,我不想删除孩子(playPart1);。我希望孩子留下来。但是 - 如果我不删除它,那么一切都会好起来的。如果我删除它,似乎它忽略了它必须在进入playPart1之前完成playGraph的事实。知道为什么会这样吗?
答案 0 :(得分:0)
我假设Chart / Part1 / Part2是MovieClip符号,当它们到达最后一帧时会调度COMPLETE事件?如果这是正确的,那么我可以对发生的事情做出相当好的猜测。
您假设您的符号在您将其添加到舞台并调用 gotoAndPlay 之前无法播放。这是不正确的,只要你实例化它将开始在后台播放的符号,也就是说,前4行代码都会创建符号并开始播放它们,即使它们在屏幕上不明显,因此,您的COMPLETE事件将在您预期之前在后台触发。
解决方案是在实例化这些符号后立即停止播放这些符号,然后在前一个COMPLETE事件触发后开始播放。
var playGraph = new Chart();
var playPart1 = new Part1();
var playPart2 = new Part2();
var playPart3 = new Part3();
//Stop the symbols from playing automatically
playPart1.stop();
playPart2.stop();
playPart3.stop();
addChild(playGraph);
playGraph.gotoAndPlay(1);
var s1:SoundOne = new SoundOne();
s1.play();
playGraph.addEventListener(Event.COMPLETE, onCompleteGraph);
playPart1.addEventListener(Event.COMPLETE, onCompletePart1);
playPart2.addEventListener(Event.COMPLETE, onCompletePart2);
function onCompleteGraph(evt:Event):void
{
playPart1.x = 370;
playPart1.y = 190;
addChild(playPart1);
playPart1.gotoAndPlay(1);
}
function onCompletePart1(evt:Event):void
{
playPart2.x = 100;
playPart2.y = 100;
addChild(playPart2);
playPart2.gotoAndPlay(1);
var s2:Sound2 = new Sound2();
s2.play();
}
function onCompletePart2(evt:Event):void
{
removeChild(playPart2);
addChild(playPart3);
playPart3.gotoAndPlay(1);
var s3:Sound3 = new Sound3();
s3.play();
}