简体   繁体   English

Actionscript 3数组

[英]Actionscript 3 Array

I have an array that has been built and passed into actionscript from javascript. 我有一个已经构建并从javascript传递到actionscript的数组。 Whilst debugging I can see the object fine but when actually using the array I'm not able to access the values. 虽然调试我可以看到对象很好,但在实际使用数组时,我无法访问这些值。 Additionally when hovering over 'keywords[i]' the tooltip pops up the correct value. 此外,当鼠标悬停在'keywords [i]'上时,工具提示会弹出正确的值。

The following snippet of code: 以下代码片段:

//build where clause
var whereClause:String = "Keyword IN (";
for(var i:int=0;i<keywords.length;i++) {
    whereClause += "'" + keywords[i] + "', ";
}

whereClause = whereClause.substr(0, whereClause.length-2);
whereClause +=") ";

results in the whereClause var being "Keyword IN ('undefined', 'undefined', 'undefined', 'undefined', 'undefined', 'undefined') " 导致whereClause var为“Keyword IN('undefined','undefined','undefined','undefined','undefined','undefined')”

I can see the array isn't a 'normal' actionscript array, in the watch window it gives it a type '__HTMLScriptArray' so this is obviously where the problem is coming from. 我可以看到数组不是'普通'的actionscript数组,在监视窗口中它给它一个类型'__HTMLScriptArray',所以这显然是问题的来源。 Any idea how to get at the data inside the __HTMLScriptArray object? 知道如何获取__HTMLScriptArray对象内的数据吗?

If your keywords array is valid, then you should build your where condition using a join: 如果您的关键字数组有效,那么您应该使用连接构建where条件:

var whereClause : String = "Keyword IN ('";
whereClause += keywords.join("', '");
whereClause += "')";

I that case you can skip your whereClause = whereClause.substr(0, whereClause.length-2); 在那种情况下你可以跳过你的whereClause = whereClause.substr(0, whereClause.length-2);

you can try using a for-in loop instead. 您可以尝试使用for-in循环。 Something like: 就像是:

for (var key:String in keywords) 
{
    trace(key, ':', keywords[key]); // trace for debugging, to see key and value
    whereClause += "'" + keywords[key] + "', ";
}

See if that works. 看看是否有效。

I've never seen this problem, is this plain Flash or Flex? 我从未见过这个问题,这是普通的Flash还是Flex? (although haven't suffered from this in either), I guess you are using ExternalInterface as well. (虽然两者都没有遭受过这种情况),我猜你也在使用ExternalInterface。 Anyway, instead of doing a normal for loop, use a for each. 无论如何,不​​是做一个正常的for循环,而是使用a for each。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM