2013-04-30 3 views
0

Это может быть глупый вопрос, так как я новичок в flash pro и не знаю слишком много. Итак, у меня есть кадр с некоторым скриптом действия (AS3), и этот скрипт запускается постоянно после запуска. Я хочу, чтобы остановить сценарий и продолжить воспроизведение фильма. Так, например, скрипт работает только между кадрами 50-100. Как это возможно?Flash - Stop AS3 после установленного количества кадров

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; 
} 
+0

Что делает скрипт делать именно? Вы говорите о прослушивании входного кадра (обновление каждой функции кадра)? –

+0

Спасибо за ответ. Он загружает вещи, которые я не понимаю, я получил его с http://www.flashandmath.com/intermediate/spot/index.html – user1130820

+0

, покажите свой код. То, что вы можете сделать в верхней части вашего обработчика фрейма ввода, - это что-то вроде 'if (currentFrame <50 && currentFrame> 100) return;'. Эта строка выходит из функции, если ваш не на кадре между 50 и 100 – BadFeelingAboutThis

ответ

0

Поскольку проект на самом деле не использует фреймы, вы можете настроить счетчик и в основном увеличить счет при вызове события ввода. Попробуйте решение ниже. Измените 200 на любое количество, которое вы хотите. Вы можете trace(counter) тоже, если вам нравится

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; 
} 

Timer будет работать, а также

+0

Спасибо, я попробую это завтра, так как мне нужно идти сейчас. Чтобы уточнить, да, весь код находится в одном кадре, потому что это то, как появился исходный файл. Но я буду добавлять другие слои и расширять временную шкалу, как только я получу это для работы. Как я уже сказал, я не знаю ничего о AS3, я просто подумал, что будет простой способ определить, как долго действие должно работать в фильме. – user1130820

+0

Поскольку вы новичок в AS3, я рекомендую НЕ использовать фреймы. Фреймы - это кадры на временной шкале. Я знаю, что это сбивает с толку, особенно с событием под названием «onEnterFrame». Даже с 1 файлом физического фрейма файл все еще имеет частоту кадров, которую вы можете изменить на панели свойств. Скорость события «ENTER_FRAME» будет зависеть от этого числа. Если вы не делаете настоящую анимацию, я предлагаю вам использовать 1-кадровый фильм и использовать сценарий действий, чтобы делать все. – Ronnie

+0

Да, это работает благодаря, но мне нужно сделать мультикадровую анимацию, и я прекрасно разбираюсь во всех этих аспектах, а не в AS3, поэтому я мог бы просто отказаться от AS3 все вместе. Я просто хочу, чтобы вспышка была немного более дружелюбной к нору и имела хорошие эффекты из коробки. – user1130820

0

При добавлении слушателя событий на 50 кадр:

this.addEventListener(Event.ENTER_FRAME, onEnter);

Затем вы можете удалить один и тот же слушателя на кадре 100:

this.removeEventListener(Event.ENTER_FRAME, onEnter);

Таким образом, onEnter будет вызываться только через кадры от 50 до 100.

+0

это не работает. OP фактически не использует никаких кадров. Весь код находится в одном кадре. – Ronnie

Смежные вопросы