A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Action Script Button Function Help

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Posts
    102

    Action Script Button Function Help

    I'm having problems with the following script I'm using for an XML photo gallery.

    for (i=0; i<49; i++) {
    if (category[i] == "online") {
    if (b<50) {
    thumbbutton = this["a"+(b+1)];
    thumbbutton.loadMovie(thumb[i], 1);
    button = this["bt"+(i+1)];
    button.onRollOver = function() {
    company_txt.text = company[i];
    description_txt.text = description[i];
    url_txt.text = url[i];

    };
    }
    b++;
    }
    }

    The "i" variable works fine until it gets to the button.onRollOver function. I did a trace and "i" is always 49. It should never be 49 because the For loop should break at 49. Any suggestions as to why this is happening? I did a trace before the function, and I got 3 and 5 - there is the "online" tag at this position in the XML. Thanks!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    add events outside of the for(loop)
    loops only update on the last iteration (hence all are 49)

    PHP Code:
    for (var i=0i<49i++) {
    if (
    category[i] == "online") {
    if (
    b<50) {
    thumbbutton this["a"+(b+1)];
    thumbbutton.loadMovie(thumb[i], 1);
    button this["bt"+(i+1)];
    addEvents(buttoni);
    }
    b++;
    }
    }

    function 
    addEvents(btn,id){
    btn.onRollOver = function() {
    company_txt.text company[id];
    description_txt.text description[id];
    url_txt.text url[id];
    };
    }; 
    hth

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