Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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:数组中带有indexOf()的大型文本文件_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3:数组中带有indexOf()的大型文本文件

Actionscript 3 AS3:数组中带有indexOf()的大型文本文件,actionscript-3,Actionscript 3,我将sowpods字典嵌入AS3中的一个数组中,然后使用indexOf()提交搜索以验证该单词的存在 当我加载一个较小的文本文件时,它似乎可以工作,但较大的文本文件却不行。由于文件是在编译过程中嵌入的,所以不应该有用于加载的事件来侦听,对吗 代码: 根据我的经验(我没有直接的文档支持),Flash无法打开非常大的文本文件。我以前在导入词典时遇到过与您相同的问题 我最终做的是将字典转换为ActionScript类,这样我就不必加载文件并将其解析为字典以更好地搜索,字典已经被解析并存储在数组中。由于

我将sowpods字典嵌入AS3中的一个数组中,然后使用indexOf()提交搜索以验证该单词的存在

当我加载一个较小的文本文件时,它似乎可以工作,但较大的文本文件却不行。由于文件是在编译过程中嵌入的,所以不应该有用于加载的事件来侦听,对吗

代码:

根据我的经验(我没有直接的文档支持),Flash无法打开非常大的文本文件。我以前在导入词典时遇到过与您相同的问题

我最终做的是将字典转换为ActionScript类,这样我就不必加载文件并将其解析为字典以更好地搜索,字典已经被解析并存储在数组中。由于数组成员已经排序,我使用了一个简单的半间隔搜索函数()来确定字典是否包含该单词

基本上,您的字典如下所示:

public class DictSOWPODS {
    protected var parsedDictionary : Array = ["firstword", "secondword", ..., "lastword"]; // yes, this will be the hugest array initialization you've ever seen, just make sure it's sorted so you can search it fast

    public function containsWord(word : String) : Boolean {
        var result : Boolean = false;
        // perform the actual half-interval search here (please do not keep it this way)
        var indexFound : int = parsedDictionary.indexOf(word);
        result = (indexFound >= 0)
        // end of perform the actual half-interval search (please do not keep it this way)
        return result;
    }
}
如果使用AS类而不是文本文件,唯一的损失就是无法在运行时更改它(除非使用swc来保存该类),但是由于您已经将文本文件嵌入到了.swf中,因此这应该是迄今为止最好的解决方案(无需加载和解析该文件)。 同样重要的是要注意,如果你的字典真的很大,flash编译器最终会在羞愧中爆炸

编辑:

我已经把我在这里找到的猪圈变成了一个工人阶级,到这里来: ?

public class DictSOWPODS {
    protected var parsedDictionary : Array = ["firstword", "secondword", ..., "lastword"]; // yes, this will be the hugest array initialization you've ever seen, just make sure it's sorted so you can search it fast

    public function containsWord(word : String) : Boolean {
        var result : Boolean = false;
        // perform the actual half-interval search here (please do not keep it this way)
        var indexFound : int = parsedDictionary.indexOf(word);
        result = (indexFound >= 0)
        // end of perform the actual half-interval search (please do not keep it this way)
        return result;
    }
}