// in paused state before it ends or calling
// pause() on it later will not work.
flyChopper.resume();
// End the effect
flyChopper.end();
// Reset assets to their original states.
helicopter.visible = true;
explosion.visible = false;
startButton.enabled = pauseButton.enabled =
resumeButton.enabled = selfDestructButton.enabled = true;
}
private function pauseChopperHandler():void
{
// Pause the Move effect on the helicopter.
flyChopper.pause();
// Calculate players score based on the inverse of the
// distance between the helicopter and the dart board.
score.text = String(Math.round(1/(helicopter.x - dartBoard.x)*10000));
pauseButton.enabled = false;
resumeButton.enabled = true;
}
private function resumeChopperHandler():void
{
flyChopper.resume();
resumeButton.enabled = false; pauseButton.enabled = true;
}
]]>
</mx:Script>
<!-- Create a Move effect with a random duration between .5 and 1.5 seconds -->
<mx:Move
id="flyChopper" target="{helicopter}"
xBy="-290" easingFunction="mx.effects.easing.Quadratic.easeIn"
duration="{Math.round(Math.random()*1500+500)}"
effectEnd="endEffectHandler();"
/>
<mx:Panel
title="Effects Chopper Game" width="100%" height="100%"
paddingTop="10" paddingLeft="10" paddingRight="10"
paddingBottom="10" horizontalAlign="right"
>
<!-- The game canvas -->
<mx:Canvas width="100%" height="100%">
<mx:Image
id="dartBoard" width="100" height="150.2"
source="{DartBoard}" x="10" y="20"
/>
<!-- Hide the explosion animation initially. -->
<mx:Image
id="explosion" source="{Explosion}"
y="50" x="0" added="explosion.visible = false;"
/>
<mx:Image
id="helicopter" width="80" height="48.5"
source="{Helicopter}" right="0" y="67"
/>
</mx:Canvas>
<!-- Instructions -->
<mx:Text
width="100%" color="#ff0000"
text="Pause the helicopter as close as possible to the dartboard without hitting it."
textAlign="center" fontWeight="bold"
/>
<mx:HBox>
<mx:Label text="Score:" fontSize="18"/>
<mx:Label id="score" text="0" fontSize="18"/>
</mx:HBox>
<mx:ControlBar horizontalAlign="right">
<mx:Button
id="startButton" label="Start"
click="flyChopper.play(); startButton.enabled=false;"
/>
<mx:Button id="pauseButton" label="Pause" click="pauseChopperHandler();"/>
<mx:Button id="resumeButton" label="Resume" click="resumeChopperHandler();"/>
<mx:Button
id="selfDestructButton" label="Self destruct!"
click="flyChopper.resume(); flyChopper.end();"
/>
<mx:Button label="Play again!" click="playAgainHandler();"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
提示: 如果调用某个效果的 end() 方法时, 该效果被暂停, 则当您再次显示相同的效果时, 调用其 pause() 方法将不会有效果。 若要解决此问题, 请在调用其 end() 方法之前调用效果上的 resume() 方法。换句话说, 在首先继续暂停的效果之前, 不要结束它