A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: onRollOver = function() --> return dynamic button name

  1. #1
    Senior Member alex8735's Avatar
    Join Date
    May 2001
    Location
    Aachen, Germany
    Posts
    117

    onRollOver = function() --> return dynamic button name

    I've got a set of dynamically created listElements wich are Buttons. When I roll over them I want them to trace thier names(numbers). The following script doesn't work, the last value of "i" is alway returned instead of the number corresponding to the aktual listElement. Any ideas??

    thx Alex

    PHP Code:
    this.onEnterFrame = function(){
      for(
    i=0;i<numElem;i++){
        
    this["listElement"+i].onRollOver = function(){
          
    trace("listElement"+i);
        }
      }

    alex8735 from Germany ICQ:61424424

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    Try:

    this.onEnterFrame = function(){
    for(i=0;i<numElem;i++){
    this["listElement"+i].onRollOver = function(){
    trace(this._name);
    }
    }
    }

    K.

  3. #3
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Not at all surprising when you think of the scope of each variable. i is defined on the time line and is not local, so all functions point to the same value ... which has been reset in making all the list elements.
    However, given that you have already named the list elements with the index number, why not use that instead.
    code:

    this.onEnterFrame = function(){
    for(i=0;i<numElem;i++){
    this["listElement"+i].onRollOver = function(){
    var n = this._name;
    var ind = n.substr("listelement".length,n.length)
    trace(n +" has index number "+ind);
    }
    }
    }


    The alternative, is to set a variable in each list element as you make them.

  4. #4
    Senior Member alex8735's Avatar
    Join Date
    May 2001
    Location
    Aachen, Germany
    Posts
    117
    Thanks

    I tried almost everything and the solution is so simple ;-)))
    alex8735 from Germany ICQ:61424424

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center