开发者

Actionscript 3 Array

开发者 https://www.devze.com 2023-03-25 03:30 出处:网络
I have an array that has been built and passed into actionscript from javascript. Whilst debugging I can see the object fine but when actually using the array I\'m not able to access the values. Addit

I have an array that has been built and passed into actionscript from javascript. 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.

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);
whereCl开发者_如何学Cause +=") ";

results in the whereClause var being "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. Any idea how to get at the data inside the __HTMLScriptArray object?


If your keywords array is valid, then you should build your where condition using a join:

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

I that case you can skip your whereClause = whereClause.substr(0, whereClause.length-2);


you can try using a for-in loop instead. 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? (although haven't suffered from this in either), I guess you are using ExternalInterface as well. Anyway, instead of doing a normal for loop, use a for each.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号