Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 设置帧数后,闪烁停止AS3_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 设置帧数后,闪烁停止AS3

Actionscript 3 设置帧数后,闪烁停止AS3,actionscript-3,flash,Actionscript 3,Flash,这可能是一个愚蠢的问题,因为我是flash pro新手,知道的不多。 因此,我有一个带有一些动作脚本(AS3)的框架,这个脚本一旦启动就会持续运行。我想要的是一种停止脚本并继续播放电影的方法。例如,脚本只在第50-100帧之间运行。这怎么可能 var sw = 496; var sh = 445; var lightRadius:Number; var frontLight:Sprite; var backLight:Sprite; var blur:BlurFilter; var textC

这可能是一个愚蠢的问题,因为我是flash pro新手,知道的不多。 因此,我有一个带有一些动作脚本(AS3)的框架,这个脚本一旦启动就会持续运行。我想要的是一种停止脚本并继续播放电影的方法。例如,脚本只在第50-100帧之间运行。这怎么可能

var sw = 496;
var sh = 445;

var lightRadius:Number;
var frontLight:Sprite;
var backLight:Sprite;
var blur:BlurFilter;
var textClip:mcText;
var textClipMask:mcText;
var textClipShadow:mcText;
var offsetX:Number;
var offsetY:Number;
var angle:Number;
var scaleFactor:Number;
var blackRectangle:Sprite;
var lightAndDark:Sprite;
var textAndLightHolder:Sprite;
var spotWidth:Number;
var spotHeight:Number;
var ambientShade:uint;
var lightOnBackWallColor:uint;

var oscillationAmplitude:Number;

init();

function init():void {

lightRadius = 50;

spotWidth = 80;
spotHeight = 80;

offsetX = 0;
offsetY = -25;
scaleFactor = 1.25;

/*
We define colors below.

The ambientShade is best set to a gray value.  By multiplication of color values, it
controls how dark the text will be when it is not illuminated by the spotlight.
Setting ambientShade to 0x000000 (black) will cause the text to be completely invisible
when not illuminated.

The wall in the background can appear to have its own color, 
by setting lightOnBackWallColor.  If lightOnBackWallColor is set to a dull gray as
we have done below, the effect is of a diffused light.
*/
ambientShade = 0x111111;
lightOnBackWallColor = 0x444444;

textClip = new mcText();
textClip.x = sw/2;
textClip.y = sh/2;

textClipMask = new mcText();
textClipMask.x = sw/2;
textClipMask.y = sh/2;

textClipShadow = new mcText();
textClipShadow.scaleX = textClipShadow.scaleY = scaleFactor;
textClipShadow.transform.colorTransform = new ColorTransform(0,0,0,1);
var shadowBlur:BlurFilter = new BlurFilter(6,6);
shadowBlur.quality = BitmapFilterQuality.HIGH;
textClipShadow.filters = [shadowBlur];
textClipShadow.x = textClip.x + offsetX;
textClipShadow.y = textClip.y + offsetY;

var matrix:Matrix = new Matrix();
matrix.createGradientBox(2*spotWidth,2*spotHeight,0,-spotWidth,-spotHeight);
frontLight = new Sprite();
frontLight.graphics.beginGradientFill("radial",[0xFFFFFF,ambientShade],[1,1],[64,255],matrix);
frontLight.graphics.drawEllipse(-spotWidth,-spotHeight,2*spotWidth,2*spotHeight);
frontLight.graphics.endFill();

matrix = new Matrix();
matrix.createGradientBox(2*scaleFactor*spotWidth,2*scaleFactor*spotHeight,0,-scaleFactor*spotWidth,-scaleFactor*spotHeight);
backLight = new Sprite();
backLight.graphics.beginGradientFill("radial",[lightOnBackWallColor,0x000000],[1,1],[32,255],matrix);
backLight.graphics.drawEllipse(-scaleFactor*spotWidth,-scaleFactor*spotHeight,2*scaleFactor*spotWidth,2*scaleFactor*spotHeight);
backLight.graphics.endFill();

frontLight.x = sw/2;
frontLight.y = sh/2;
backLight.x = frontLight.x + offsetX;
backLight.y = frontLight.y + offsetY;

blackRectangle = new Sprite();
blackRectangle.graphics.beginFill(ambientShade);
var rect = textClip.getBounds(textClip);
blackRectangle.graphics.drawRect(rect.left-2, rect.top-2, rect.width+4, rect.height+4);
blackRectangle.graphics.endFill();
blackRectangle.x = sw/2;
blackRectangle.y = sh/2;

lightAndDark = new Sprite();
lightAndDark.addChild(blackRectangle);
lightAndDark.addChild(frontLight);


lightAndDark.blendMode = BlendMode.MULTIPLY;

textAndLightHolder = new Sprite();

this.addChild(backLight);
this.addChild(textClipShadow);
this.addChild(textAndLightHolder);
textAndLightHolder.addChild(textClip);
textAndLightHolder.addChild(lightAndDark);
this.addChild(textClipMask);

textAndLightHolder.mask = textClipMask;

oscillationAmplitude = (sw/2 - backLight.width/2)/scaleFactor - 2;

this.addEventListener(Event.ENTER_FRAME, onEnter);  
}

function onEnter(evt:Event):void {
frontLight.x = 0.5*sw - oscillationAmplitude*Math.cos(getTimer()*0.0005);
backLight.x = 0.5*sw - scaleFactor*(0.5*sw-frontLight.x) + offsetX;
}

如果要在第50帧上添加事件侦听器:

this.addEventListener(Event.ENTER\u FRAME,onEnter)

然后,您可以删除第100帧上的相同侦听器:

this.removeEventListener(Event.ENTER\u FRAME,onEnter)


通过这种方式,onEnter函数只能在第50帧到第100帧之间调用。

由于项目实际上没有使用帧,因此可以设置计数器,并在调用enter frame事件时基本上增加计数。尝试下面的解决方案。将
200
更改为您想要的任何数字。如果您愿意,也可以
跟踪(计数器)

var sw = 600;
var sh = 320;

var lightRadius:Number;
var frontLight:Sprite;
var backLight:Sprite;
var blur:BlurFilter;
var textClip:mcText;
var textClipAmbient:mcText;
var textClipShadow:mcText;
var offsetX:Number;
var offsetY:Number;
var angle:Number;
var scaleFactor:Number;
var textCenterX:Number;
var textCenterY:Number;
var illuminatedTextColor:uint;
var ambientColor:uint;
var lightOnBackWallColor:uint;
var counter:Number = 0; //-- Define a variable, counter

init();

function init():void {

    textCenterX = sw/2;
    textCenterY = sh/2 - 10;

    lightRadius = 53;

    /*
    We define colors below.
    illuminatedTextColor is the color of the text when it is fully 
    illuminated by the spotlight.

    The ambient color is the color of the text when it is not illuminated.
    Setting ambient color to 0x000000 (black) makes the text completely invisible when
    not under the spotlight.

    The wall in the background can appear to have its own color, 
    by setting lightOnBackWallColor.  If lightOnBackWallColor is set to a dull gray as
    we have done above, the effect is of a diffused light.
    */
    ambientColor = 0x000000;
    illuminatedTextColor = 0xFFFFFF;
    lightOnBackWallColor = 0x555555;

    //Try different colors to see the effect:
    //ambientColor = 0x181111;
    //illuminatedTextColor = 0xFF4444;
    //lightOnBackWallColor = 0x556066;

    //the offset parameters determine where the shadow will lie.
    //The scaleFactor determines how large the shadow will be compared to
    //the text.  A large shadow suggests a wall further back (or the light being closer).
    offsetX = 0;
    offsetY = -40;
    scaleFactor = 1.25;

    textClip = new mcText();
    textClip.x = textCenterX;
    textClip.y = textCenterY;

    textClipAmbient = new mcText();
    textClipAmbient.x = textClip.x;
    textClipAmbient.y = textClip.y;
    var red:Number = (ambientColor >> 16);
    var green:Number = (ambientColor >> 8) & 0xFF;
    var blue:Number = ambientColor & 0xFF;
    textClipAmbient.transform.colorTransform = new ColorTransform(0,0,0,1,red,green,blue);

    textClipShadow = new mcText();
    textClipShadow.scaleX = textClipShadow.scaleY = scaleFactor;
    textClipShadow.transform.colorTransform = new ColorTransform(0,0,0,1);
    var shadowBlur:BlurFilter = new BlurFilter(5,5);
    shadowBlur.quality = BitmapFilterQuality.HIGH;
    textClipShadow.filters = [shadowBlur];
    textClipShadow.x = textClip.x + offsetX;
    textClipShadow.y = textClip.y + offsetY;

    var matrix:Matrix = new Matrix();
    matrix.createGradientBox(2*lightRadius,2*lightRadius,0,-lightRadius,-lightRadius);
    frontLight = new Sprite();
    frontLight.graphics.beginGradientFill("radial",[illuminatedTextColor,ambientColor],[1,1],[16,255],matrix);
    frontLight.graphics.drawEllipse(-lightRadius,-lightRadius,2*lightRadius,2*lightRadius);
    frontLight.graphics.endFill();

    matrix = new Matrix();
    matrix.createGradientBox(2*scaleFactor*lightRadius,2*scaleFactor*lightRadius,0,-scaleFactor*lightRadius,-scaleFactor*lightRadius);
    backLight = new Sprite();
    backLight.graphics.beginGradientFill("radial",[lightOnBackWallColor,0x000000],[1,1],[16,255],matrix);
    backLight.graphics.drawEllipse(-scaleFactor*lightRadius,-scaleFactor*lightRadius,2*scaleFactor*lightRadius,2*scaleFactor*lightRadius);
    backLight.graphics.endFill();

    frontLight.x = textCenterX;
    frontLight.y = textCenterY+15;
    backLight.x = frontLight.x + offsetX;
    backLight.y = frontLight.y + offsetY;

    this.addChild(backLight);
    this.addChild(textClipShadow);
    this.addChild(textClipAmbient);
    this.addChild(frontLight);
    this.addChild(textClip);
    frontLight.mask = textClip;

    this.addEventListener(Event.ENTER_FRAME, onEnter);

}

function onEnter(evt:Event):void {
    counter++; //-- Increase the counter var
    //-- When counter is 200, stop the enter frame event
    if (counter > 200) this.removeEventListener(Event.ENTER_FRAME, onEnter); 
    frontLight.x = textCenterX - 0.3*sw*Math.cos(getTimer()*0.0006);
    backLight.x = textCenterX - scaleFactor*(textCenterX-frontLight.x) + offsetX;
}

计时器
也可以工作

脚本的具体功能是什么?你说的是输入帧侦听器(每帧更新一次函数)?谢谢你的回复。它做了一大堆我不懂的事情,我是从显示你的代码中得到的。在enterframe处理程序的顶部可以执行类似于
if(currentFrame<50&¤tFrame>100)返回的操作。如果未在50到100之间的帧上添加完整代码,则该行退出函数,其中将“if(currentFrame<50&¤tFrame>100)return;”坐在“
onEnter
函数”的顶部。虽然这真的是在帧(时间线帧)上运行的吗?听起来好像不太对劲。这行不通。OP实际上没有使用任何帧。所有的代码都放在一个框架中。谢谢,我明天会试试这个,因为我现在得走了。详细地说,是的,所有代码都放在一个框架中,因为源文件就是这样产生的。但我会添加其他层,并扩大时间表,一旦我得到这个工作。正如我所说,我对AS3一无所知,我只是想有一个简单的方法来定义动作在电影中应该持续多长时间。因为你是AS3的新手,我建议你不要使用框架。帧是时间线上的帧。我知道它令人困惑,尤其是一个名为
onEnterFrame
的事件。即使使用1物理帧文件,该文件仍具有帧速率,您可以在“属性”面板中更改该帧速率。
ENTER_FRAME
事件的速度将基于该数字。除非你做的是真实的动画,否则我建议你坚持使用一帧电影,并使用动作脚本来完成所有事情。是的,这很有效,谢谢,但我确实需要做多帧动画,我对所有这些方面都很好,只是不是AS3,所以我可能只是将AS3全部删除。我只希望flash对noob更友好一点,有一些开箱即用的好效果。