开发者

specify a function to be called

开发者 https://www.devze.com 2023-03-04 08:29 出处:网络
I have this script for random letter cycling below. I want to call this function to happen at a certain click or frame label, but when I call it with tweenmax, I get a runtime error. Can anyone explai

I have this script for random letter cycling below. I want to call this function to happen at a certain click or frame label, but when I call it with tweenmax, I get a runtime error. Can anyone explain to me how to call this function at certain events. I know this is definitely not best practice but have to try somewhere and here is what I did:

var targetWord:String = 'home';
var wordSoFar:String = '';
var possibleCharacters:Array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
var ticksBetweenLetters:int = 15;
var currentTick:int = 0;


addEventListener(Event.ENTER_FRAME, eFrame);


function eFrame(e:Event):void{
    if(currentTick >= ticksBetweenLetters){
        wordSoFar = targetWord.substr(0, wordSoFar.length + 1);
        currentTick = 0;
        ticksBetweenLetters = int(Math.random() * 15);
        if(wordSoFar == targetWord){
            removeEventLis开发者_运维知识库tener(Event.ENTER_FRAME, eFrame);
            home.home_title.field.text = targetWord;
            return;
        }
    }

    home.home_title.field.text = wordSoFar + possibleCharacters[int(Math.random() * possibleCharacters.length)];
    currentTick++;    
}

I want the event to start when I place it in here:

tl.append(TweenMax.from(home.home_title.field, 1, {onStart:eFrame}));

but I get this:

ArgumentError: Error #1063: Argument count mismatch on sncc_fla::website_1/eFrame(). Expected 1, got 0.
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at com.greensock::TweenMax/renderTime()
    at com.greensock::TimelineMax/renderTime()
    at com.greensock.core::TweenCore/setTotalTime()
    at com.greensock::TimelineMax/set currentTime()
    at com.greensock::TweenLite/renderTime()
    at com.greensock.core::SimpleTimeline/renderTime()
    at com.greensock::TweenLite$/updateAll()


Simply make your parameter optional:

function eFrame(e:Event = null):void {

You can do this, because you do not use e in your listener function.

Another way would be to give TweenMax some parameters for the function call.

tl.append(TweenMax.from(home.home_title.field, 1, {onStart:eFrame, onStartParams: [null]}));
0

精彩评论

暂无评论...
验证码 换一张
取 消