1

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?

2
  • How are you passing the data from JS to Flash? Commented Aug 3, 2011 at 11:49
  • Yes, please answer where the data comes from exactly. Commented Aug 3, 2011 at 12:20

3 Answers 3

3

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);

Sign up to request clarification or add additional context in comments.

1 Comment

Thats neater code (and it worked). Thanks :) Though I should try to use a parameter and not build the where clause like this as it's used in a SQLStatement object which are pre complied. However if you change the .text property it will (understandably) have to be complied again.
1

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.

2 Comments

The difference is probably that your __HTMLScriptArray is not a flash Array type, but an object using strings as keys rather than integers. The for-in loop gives you the keys you need to access the values.
That's what I guessed at but why does hovering over keywords[i] (whilst debuging) give you the correct value in the tooltip?
0

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.

2 Comments

I'm using Flex. I'm not using ExternalInterface. I have an initialization method that registers (or attaches) a series of methods for a 'mx:HTML' object. I can use a work around where I pass in a pipe delimited string and turn that into an array. But I thought the original problem was interesting.
I guess the problem comes from not directly using ExternalInterface then. I've never used your method for something like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.