当用户在浏览器中切换标签时,为什么 flash 应用程序会暂停?如何防止?,我需要让它连续播放
更新:
<?xml version="1.0"?>
<s:Module
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init();"
xmlns:MyComp="components.*">
<fx:Script>
<![CDATA[
import library.TicketCard;
import library.UtilFunctions;
[Embed(source="../images/ball1.png")]
private var red:Class;
[Embed(source="../images/ball2.png")]
private var orange:Class;
[Embed(source="../images/ball3.png")]
private var blue:Class;
[Embed(source="../images/ball4.png")]
private var green:Class;
[Embed(source="../images/ball5.png")]
private var purple:Class;
private var numTimer:Timer;
private var step:int;
public var currentRand:Number;
public var randNumbers:Array;
public var vNum:Array;
public var speedAnim:Number;
[Bindable]
public var countNum:int = 0;
public var ticketsBought:*;
private function init():void {
vNum = new Array();
step = 1;
ticketsBought = parentApplication.m_ticket.child.ticketsBought;
speedAnim = 1000;
generateNumbers();
randNumbers = new Array();
for(var i:int = 0; i < 90; i++)
{
randNumbers.push((i + 1));
}
numTimer = new Timer(1000, 180);
numTimer.addEventListener(TimerEvent.TIMER, onTick);
numTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTickComplete);
initialPosition();
numTimer.start();
}
private function initialPosition():void {
bigBall.width = 4;
bigBall.height = 4;
bigBall.horizontalCenter = -92;
bigBallLabel.horizontalCenter = bigBall.horizontalCenter;
bigBallLabel.setStyle('fontSize', 1);
}
private function onTickComplete(e:TimerEvent):void {
parentApplication.showMessage('end game!');
}
private function onTick(e:TimerEvent):void {
if(step == 1)
{
if(countNum < 90)
{
countNum++;
}
var rand:Number = UtilFunctions.randomRange(randNumbers.length - 1, 0);
currentRand = randNumbers[rand];
for(var i:int = 0; i < ticketsBought.length; i++)
{
var ticket:* = ticketsBought[i];
var numbers:Array = ticket.ticketNumbers;
for(var j:int = 0; j < numbers.length; j++)
{
if(numbers[j].text == currentRand)
{
var num:* = numbers[j];
num.setStyle('backgroundColor', '#552c68');
num.setStyle('color', '#FFFFFF');
ticket.checkedNumbers++;
break;
}
}
}
randNumbers.splice(rand, 1);
var n:* = vNum[rand];
n.alpha = 1;
vNum.splice(rand, 1);
bigBallLabel.text = currentRand.toString();
startIncreaseAnim();
}
else
if(step == 2)
{
startReduceAnim();
}
numTimer.stop();
}
private function generateNumbers():void {
for(var i:int = 0; i < 90; i++)
{
var m:MyImg = new MyImg();
var c:Canvas = new Canvas();
var l:Label = new Label();
l.text = (i + 1).toString();
l.horizontalCenter = 0;
l.verticalCenter = 0;
c.width = 25;
c.height = 25;
c.alpha = 0.3;
vNum.push(c);
m.horizontalCenter = 0;
m.verticalCenter = 0;
if(i >= 0 && i < 18)
{
m.source = red;
}
else if(i >= 18 && i < 36)
{
m.source = orange;
}
else if(i >= 36 && i < 54)
{
m.source = blue;
}
else if(i >= 54 && i < 72)
{
m.source = green;
}
else if(i >= 72 && i < 90)
{
m.source = purple;
}
c.addChild(m);
c.addChild(l);
numbersBlock.addChild(c);
}
}
public function startIncreaseAnim():void {
stage.addEventListener(Event.ENTER_FRAME, increaseAnim);
}
public function startReduceAnim():void {
stage.addEventListener(Event.ENTER_FRAME, reduceAnim);
}
public function endIncreaseAnim():void {
stage.removeEventListener(Event.ENTER_FRAME, increaseAnim);
}
public function endReduceAnim():void {
stage.removeEventListener(Event.ENTER_FRAME, reduceAnim);
}
public function increaseAnim(e:Event):void {
bigBall.width += 4;
bigBall.height += 4;
bigBall.horizontalCenter += 4;
bigBallLabel.horizontalCenter = bigBall.horizontalCenter;
bigBallLabel.setStyle('fontSize', bigBallLabel.getStyle('fontSize') + 1);
if(bigBall.horizontalCenter >= 0)
{
step = 2;
endIncreaseAnim();
numTimer.start();
}
}
public function reduceAnim(e:Event):void {
bigBall.width -= 4;
bigBall.height -= 4;
bigBall.horizontalCenter += 4;
bigBallLabel.horizontalCenter = bigBall.horizontalCenter;
bigBallLabel.setStyle('fontSize', bigBallLabel.getStyle('fontSize') - 1);
if(bigBall.horizontalCenter >= 90)
{
step = 1;
initialPosition();
endReduceAnim();
numTimer.start();
}
}
]]>
</fx:Script>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
</fx:Style>
<mx:VBox height="727" width="176" styleName="leftBar" verticalGap="4">
<mx:Box verticalGap="12">
<mx:Box width="176" horizontalScrollPolicy="off">
<mx:Canvas width="100%" height="100" id="bigBallWrapper" horizontalScrollPolicy="off">
<MyComp:MyImg id="bigBall" verticalCenter="0" horizontalCenter="0" source="@Embed(source='../images/ball1-1.png')"/>
<s:Label color="#000000" id="bigBallLabel" fontSize="24" text="45" verticalCenter="0" horizontalCenter="0" />
</mx:Canvas>
<mx:Canvas width="100%">
<s:Label text="ball # {countNum}" fontSize="18" verticalCenter="0" horizontalCenter="0" />
</mx:Canvas>
</mx:Box>
<MyComp:MyImg id="bingoLeft" source="@Embed(source='../images/bingoLeft.png')"/>
</mx:Box>
<mx:Tile fontSize="12" fontFamily="bor" color="black" direction="vertical" horizontalGap="9" height="100%" width="100%" paddingLeft="8" paddingRight="8" id="numbersBlock" verticalScrollPolicy="off" horizontalScrollPolicy="off">
</mx:Tile>
</mx:VBox>
</s:Module>
有点复杂的代码:),但是计时器第一次执行,然后停止,在每个动画开始后,我将它用作 setTimeout(在 js 中)