简体   繁体   中英

Actionscript 3 Array

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);
whereClause +=") ";

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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