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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 1120:访问未定义的属性squareSpeed_Actionscript 3_Flash_Undefined - Fatal编程技术网

Actionscript 3 1120:访问未定义的属性squareSpeed

Actionscript 3 1120:访问未定义的属性squareSpeed,actionscript-3,flash,undefined,Actionscript 3,Flash,Undefined,好的,我已经尝试了一些类似问题的解决方案,我已经看到了答案,但没有能够解决这个问题。这是密码 package { import flash.events.*; import flash.display.MovieClip; import Game.C; public class GameController extends MovieClip { public function startGame() { stage.addEventListener(Event.EN

好的,我已经尝试了一些类似问题的解决方案,我已经看到了答案,但没有能够解决这个问题。这是密码

package {

import flash.events.*;
import flash.display.MovieClip;
import Game.C;

public class GameController extends MovieClip {
    public function startGame() {
        stage.addEventListener(Event.ENTER_FRAME, gameLoop);
    }

    function gameLoop(evt: Event): void {

        //Handle User Input

        //Handle Game Logic

        cpuSquare.x += C.squareSpeed;
        cpuSquare.y += C.squareSpeed;

        //Handle Display


    }
}
}
然后从游戏包

package Game
{

public class C 
{
    public var squareSpeed:int = 3;
}

}

您正在尝试引用静态属性。静态属性是属于该类而不是该类实例的属性

要解决此问题,必须将squareSpeed设置为静态属性

public static var squareSpeed:int=3

否则,您将不得不创建一个C实例并使用它,但我不认为这是您在这里要做的

以下是你将如何做,以防万一

var cInstance:C = new C();
cpuSquare.x += cInstance.squareSpeed;
cpuSquare.y += cInstance.squareSpeed;

好的,谢谢!我是as3新手,使用多个文件,所以我非常感谢。