如何阻止我的雪码在其他场景中发生

时间:2013-04-26 22:55:54

标签: flash actionscript

我在AIR应用程序上处理Actionscript 3代码,在中间场景之一。当我滑到另一个场景时,雪会刷新并继续下降。我应该在场景之前和之后使用下面显示的雪码放入什么代码,以阻止雪码再次发生?

"stop();  

//Snow Flake Animation start

var snowarr = new Array();

var maxflakes:int = 60;

for(var s:int = 0; s<maxflakes; s++)
{
    var sf:snowflake = new snowflake();
    addChild(sf as DisplayObject);
    sf.x = Math.random()*stage.stageWidth;
    sf.y = 0-Math.random()*stage.stageWidth;
    var snowsize:Number = .3+(Math.random()*.6);
    sf.scaleX = sf.scaleY = sf.snowsize = snowsize;
    snowarr.push(sf);
    sf.cacheAsBitmap = true;
}

for(s = 0; s<maxflakes; s++)
{
    sf = new snowflake();
    addChild(sf as DisplayObject);
    sf.x = Math.random()*stage.stageWidth;
    sf.y = 0-Math.random()*stage.stageWidth;
    snowsize = .9+(Math.random()*.6);
    sf.scaleX = sf.scaleY = sf.snowsize = snowsize;
    snowarr.push(sf);
    sf.cacheAsBitmap = true;
}

function updateFlakes(event:Event):void
{
    for(var f:int = 0; f<(maxflakes*2); f++)
    {
        snowarr[f].y+=snowarr[f].snowsize*4;
        if(snowarr[f].y>stage.stageHeight)
        {
            snowarr[f].y-=stage.stageHeight;
        }
    }
}

addEventListener(Event.ENTER_FRAME, updateFlakes);
//Snow flake Animation End"

1 个答案:

答案 0 :(得分:0)

function set showSnow(b:boolean):void{
      if (b) {
              addEventListener(Event.ENTER_FRAME, updateFlakes);
      }else{
              removeEventListener(Event.ENTER_FRAME, updateFlakes);
              /* add some routines to remove any flakes currently on the stage */
      }
    }



Now, when you change pages, call this function to turn the snow on and off.
小心, 利