ActionScript 错误 - 1086:左大括号前需要有分号吗?

发布于 2024-11-04 18:09:39 字数 395 浏览 0 评论 0原文

我正处于创建自己的在线多人问答游戏的最初阶段,我正在做这个教程 当我在与第一帧和动态文本字段关联的动作脚本中遇到编译错误(标题中)时:

onClipEvent (load) {
  loadVariables("http://localhost/read.php?file=testfile", this, "GET");
}

我不确定我做错了什么?使用Flash CS5...这段代码是否不兼容CS3之类的?任何帮助将不胜感激,我一个小时以来一直在努力找出我做错了什么! :)

谢谢!

I am in the very beginning stages of creating my own online multiplayer trivia game and I was doing this tutorial when I ran into a compile error (in title) in the actionscript associated with the 1st frame and the dynamic text field:

onClipEvent (load) {
  loadVariables("http://localhost/read.php?file=testfile", this, "GET");
}

I am not sure what I am doing wrong? Using Flash CS5...is this code not compatible for CS3 or something? Any help would be appreciated, I have been trying to find out what I am doing wrong for like an hour! :)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

樱花细雨 2024-11-11 18:09:39

您的主要问题是您正在编写 Actionscript 2,而您的项目很可能设置为 Actionscript 3。onClipEvent 是 Actionscript 1 的旧遗产,因此该教程充其量已经过时了。

您的加载代码(在 AS3 中)应该看起来更像这样:

var loader:URLLoader = new URLLoader();

// specify format as being variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

loader.addEventListener(Event.COMPLETE, handleLoadComplete);

// load your data
loader.load(new URLRequest("foo.php")); 

function handleLoadComplete (e):void {
    trace(loader.data is URLVariables); // true
    trace(loader.data.valueFromYourData);
}

Your main problem is that you are coding Actionscript 2 while your project is very likely set to be Actionscript 3. onClipEvent is an old heritage from Actionscript 1, so, that tutorial is outdated at best.

Your loading code (in AS3) should look more like this:

var loader:URLLoader = new URLLoader();

// specify format as being variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

loader.addEventListener(Event.COMPLETE, handleLoadComplete);

// load your data
loader.load(new URLRequest("foo.php")); 

function handleLoadComplete (e):void {
    trace(loader.data is URLVariables); // true
    trace(loader.data.valueFromYourData);
}
妳是的陽光 2024-11-11 18:09:39

我不熟悉 Flash,但作为 Flex 开发人员,我猜测您的代码是函数声明(事件处理程序)。在严格的 ActionScript 中,您可以这样声明它:

protected function onClipEvent(load: Event): void {
  loadVariables("http://localhost/read.php?file=testfile", this, "GET");
}

I'm not familiar with Flash, but as a Flex developer I would guess that your code is a function declaration (event handler). In strict ActionScript you would declare it like this:

protected function onClipEvent(load: Event): void {
  loadVariables("http://localhost/read.php?file=testfile", this, "GET");
}
寄离 2024-11-11 18:09:39

嗯,看起来那个教程有一些错误,因为我认为你想写“function onClipEvent(load)”,我很惊讶建议的修复启动没有改变任何东西,要么修复问题,要么至少生成一个不同的错误。您绝对确定您使用更改后的代码运行了它吗?

该错误的另一个可能原因(实际上是大多数语法错误)是之前的代码中的错误,因此我们可能需要您发布更多代码,然后仅发布该函数。括号错误通常是由于未正确关闭前一个代码块引起的(例如,在粘贴新代码时意外删除括号):

function somethingOrOther() {
  blah

function onClipEvent(load) {  //error!
  stuff
}

hm it looks like that tutorial has some mistakes, because I think you want to write "function onClipEvent(load)" I'm surprised the fix splash suggested didn't change anything, either fixing things or at least generating a different error. Are you absolutely sure you ran it with the changed code?

Another probable cause for that error (most syntax errors actually) is a mistake in the code before it so we may need you to post more of your code then just that one function. Errors with brackets are often caused by not properly closing the previous code block (eg. accidentally deleting a bracket while pasting in new code):

function somethingOrOther() {
  blah

function onClipEvent(load) {  //error!
  stuff
}
画中仙 2024-11-11 18:09:39

我认为您在这些行之前做错了一些事情,可能缺少 ;
只是为了测试,将其写为

;onClipEvent (load)

“也分享上面的行”
希望有效

I think you are doing some thing wrong before these lines, may be ; is missing
just for test write it as

;onClipEvent (load)

Also share above lines
hopes that works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文