Named views will show up as attributes of their parent. The correct way to reference an attribute with a computed name in Javascript is to use the [] operator. If your code below is in a method in the parent view you would say:

 this['pul'+(temp.toString())].setPulPosition(x,y);

(You don't actually need the toString, since + on a String and a Number will coerce the number to a string automatically.)

In JavaScript,
 foo.bar
and
 foo['bar']
are the same, except in the second case you could also say
 foo['b'+'a'+'r']
You can use any expression to calculate the name of the attribute.

On Jul 6, 2009, at 15:44, cem sonmez <[email protected]> wrote:

Hi
I have a class named "pul" and i have created some instances like that : <pul name="pul1" /><pul name="pul2" /><pul name="pul3" /><pul name="pul4" />

in a method, i want to use these objects whose names should be specified with the i variable in a for expression

i.e. :

for (var i=0; i<4; i++) {
var temp= i+1;
  'pul'+(temp.toString()).
setPulPosition(x,y);
}

But with this use, it is incorrect. Bec. 'pul'+(temp.toString()) is a String and i need "pul" object to use the appropriate method, i know the problem but i i have no idea how to do that.

Any idea?
Best regards.


--
Cem SONMEZ

Reply via email to