0

I have some variables a1 to a14 and another set of variables q1 to q14 , and I am trying to do a for loop like this

for(var i:uint = 1; i < 15; i++)
{ 
 if (this("a"+i).x== this("q"+i).x )
{points= points+1 }
else
{
this("q"+i.visible=false;
// shows the good answer 
 }
} 

Please help :)

1
  • What do you think about this line... this("q"+i.visible=false; Commented Oct 31, 2011 at 17:23

1 Answer 1

1

Properties of objects can be accessed via square brackets, similar to indexes in an array. Each property name (the variable name) is actually a variable key. It is also recommended to CHECK that the object actually HAS the property, using the Object.hasOwnProptery(propertyName:String) method.

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001424.html

Example:

 for(var i:uint = 1; i < 15; i++){ 
    if (this["a"+i].x== this["q"+i].x ){
        points= points+1;
    }
    else{
        this["q"+i].visible=false;
        // shows the good answer 
    }
} 

I have not checked, but it may be wise to use Number instead of uint and toString to retrieve it's string value when creating the variable name

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

1 Comment

uint is fine (actually, preferable) in this case.

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.