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
在flash as2中跟踪从文本文件加载的变量时,会得到未定义的值_Flash_Variables_Actionscript 2_Undefined - Fatal编程技术网

在flash as2中跟踪从文本文件加载的变量时,会得到未定义的值

在flash as2中跟踪从文本文件加载的变量时,会得到未定义的值,flash,variables,actionscript-2,undefined,Flash,Variables,Actionscript 2,Undefined,我正在使用Swishmax 4,我想从flash的外部txt文件加载一个变量。 我已经创建了一个动态文本来加载我的变量。它工作得很好,但是当我想要跟踪变量时,我得到了一个未定义的值。这是我的密码: file.txt &cont=data &myVar=Hello World!!& &yourVar=finally there!!& &yourAge=24& &loadedDone=1& 代码 onFrame (1) {

我正在使用Swishmax 4,我想从flash的外部txt文件加载一个变量。
我已经创建了一个动态文本来加载我的变量。它工作得很好,但是当我想要跟踪变量时,我得到了一个未定义的值。这是我的密码:

file.txt

&cont=data
&myVar=Hello World!!&
&yourVar=finally there!!&
&yourAge=24&
&loadedDone=1&
代码

onFrame (1) {
    this.loadVariables("file.txt");
    trace(cont); // i get an undefined value here
}

我该怎么办?

我真的不知道为什么,但我修改了这个脚本并正确调试了它

onSelfEvent (load) {
    this.loadVariables("file.txt");
}
onFrame (3) {
    trace(cont);
}

您不需要指定file.txt的内容,也不需要指定它是否与swf本身位于同一文件夹中。 但是,您应该始终考虑到,加载过程需要一些时间,因此您不应该期望代码在远程服务器上工作(至少,不是第一次运行swf文件)。如何确保文件在第0帧(onLoad事件)之前加载?事实上你不能。 在第二个脚本中,您尝试稍后访问数据,因此数据很可能已加载

因此,您必须找到一种方法来确保文件加载正常,并且有几种方法可以做到这一点:使用loadVars类(推荐)或在file.txt本身中使用另一个变量,并检查其值是否已定义。第二种方法的示例可以是:

文件txt

&cont=data
&myVar=Hello World!!&
&yourVar=finally there!!&
&yourAge=24&
&loadedDone=1&
swi代码:

onSelfEvent(load){
  this.loadVariables("file.txt");
}
onFrame(2){
  if(loadedDone!= 1)prevFrameAndPlay(); // Wait till the file is loaded
}
onFrame(3){!!
  // Once the data is loaded, display variable values!!
  trace(myVar);
  trace(yourVar);
  trace(yourAge);
}
但是这种方法存在一个问题,即如果未定义变量loadeDone,或者file.txt不存在,您的swi文件将陷入一个无休止的循环中。因此,您最好尝试一下loadVars类,或者为此使用XML

你好,坎克雷索