Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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)TypeError:尝试在每一帧上调用函数时出错#1009_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 (AS3)TypeError:尝试在每一帧上调用函数时出错#1009

Actionscript 3 (AS3)TypeError:尝试在每一帧上调用函数时出错#1009,actionscript-3,flash,Actionscript 3,Flash,首先,让我先说我对ActionScript3非常陌生。 我有一个需要在每一帧上调用的函数。所以我把这个函数放到框架中,然后我制作了一个电影剪辑,并给它命名为“StageFrame” 这是我的代码: const NUM_BALL:int = 24; var loadingBall:Vector.<Shape> = new Vector.<Shape (NUM_BALL); var timeStep:int = 0; const BALL_HEIGHT:int = 40;

首先,让我先说我对ActionScript3非常陌生。 我有一个需要在每一帧上调用的函数。所以我把这个函数放到框架中,然后我制作了一个电影剪辑,并给它命名为“StageFrame”

这是我的代码:

const NUM_BALL:int = 24;
var loadingBall:Vector.<Shape> = new Vector.<Shape (NUM_BALL);
var timeStep:int = 0;
const BALL_HEIGHT:int = 40;

    function animateBalls(e:Event):void
    {
        for (var i:int = 0; i < NUM_BALL; i++ )
        {
        loadingBall[i].graphics.clear();
        loadingBall[i].graphics.beginFill(0x0B5F95);
        loadingBall[i].graphics.drawCircle(455+5*i,getY(i,timeStep),2);
    }
    timeStep++;
}

function getY(i:int, t:int):int
{
    return 260 + BALL_HEIGHT/2 * (1 + Math.sin((timeStep * (i/500 + 0.02)) % 2*Math.PI));
}

StageFrame.addEventListener(Event.ENTER_FRAME, animateBalls); 
const NUM\u BALL:int=24;

var loadingBall:Vector.=新向量。当然,您会得到
错误#1009
错误,因为在将
形状设置为
动画球()函数之前,您尚未创建
形状

所以你可以这样做:

var loadingBall:Vector.<Shape>  = new Vector.<Shape> ();

// create your Shape objects and add it to your stageFrame MovieClip
for (var i:int = 0; i < NUM_BALL; i++)
{
    var shape:Shape = new Shape();

    // add your shape to your loadingBall Vector
    loadingBall.push(shape);

    // add your shape to your stageFrame
    stageFrame.addChild(shape);     
    // it's better to start with a lowercase letter for an object name, uppercase letter is for Class names
} 

function animateBalls(e:Event):void 
{
    var shape:Shape;
    for (var i:int = 0; i < loadingBall.length; i++)
        shape = loadingBall[i];
        shape.graphics.clear();
        shape.graphics.beginFill(0x0B5F95);
        shape.graphics.drawCircle(455 + (5*i), getY(i, timeStep), 2);
    }
    timeStep++;

}
var加载球:向量新载体。();
//创建形状对象并将其添加到stageFrame MovieClip中
for(变量i:int=0;i
希望这能有所帮助