我正在使用flash cs5制作一个寓教于乐的游戏,我对使用flash真的很陌生,事实上我们在学校从来没有接触过它,但我坚持学习它。
在我的代码中,我遇到了这个错误
C:\Users\acer\Desktop\JikanLibrary\Main.as, Line 16 1119: Access of possibly undefined property Click through a reference with static type Class.
这是我在程序中使用的代码
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var startPage:StartPage;
var jikanBookshelf:JikanBookshelf;
public function Main()
{
startPage = new StartPage;
jikanBookshelf = new JikanBookshelf;
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
addChild(startPage);
function onJikanBookshelf(event:MouseEvent):void
{
addChild(jikanBookshelf);
removeChild(startPage);
}
}
}
}
错误在这一行
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
由于我对Flash很陌生,我真的不知道我的代码出了什么问题,在我放置鼠标事件之前它已经工作了一段时间。我希望有人能帮助我。
最佳答案
ActionScript 是区分大小写的语言。这意味着 Click
与 CLICK
不同。所以你需要的是MouseEvent.CLICK
“为什么 CLICK 全部大写?大多数属性名称都不是。”,您可能会问。
这是因为 CLICK 是 MouseEvent 的一个静态常量属性,而 ActionScript(和许多其他语言)程序员之间的约定是静态常量全部以大写形式编写,以便在视觉上将它们与其他变量区分开来。
- “static”表示它是 MouseEvent 类的属性,而不是 MouseEvent 实例的属性。
- “const”表示它不是变量:您无法更改它的值。
关于actionscript-3 - 1119 :Access of possibly undefined property Click through a reference with static type Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7138938/