A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: attachMovie() problem

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Posts
    1

    attachMovie() problem

    Hi , i'm new to actionscript. I use this code to get a button instance from my library several times into stage. The problem is that although the code should add 9 buttons to stage, it loads only the last one correctly. It also adds a button at 0,0 (top left of the movie) but with no functionality.

    the code used is:
    for (var i=1 ; i <= loader.num ; i++) { //my for loop

    var elementtodisplay = new LoadVars();
    elementtodisplay.onLoad = function(success) {
    if(success) {

    _root.attachMovie("lampon", "button_"+i, _root.getNextHighestDepth());

    _root["button_"+i]._x=elementtodisplay.detx;
    _root["button_"+i]._y=elementtodisplay.dety;
    _root["button_"+i].id=elementtodisplay.id;
    _root["button_"+i].onPress=function(){

    getURL("http://www.oneurl.com"+_root["button_"+i].id);

    } // end onpress
    _root["button_"+i].play();
    } //end if success
    }; // end function success

    var sender = new LoadVars();
    sender.n = i;
    sender.f=floortodisplay.num;
    sender.sendAndLoad("elementtoshow.php", elementtodisplay, "post");

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Not tested, but i think it should look more like this:
    code:
    var elementtodisplay = new LoadVars();
    elementtodisplay.onLoad = function(success) {
    if (success) {
    for (var i=1; i <= _root.loader.num; i++) {//don't know where loader.num is??
    _root.attachMovie("lampon", "button_"+i, _root.getNextHighestDepth() , [_x:this.detx,_y:this.dety]);
    _root["button_"+i].id = this.id;
    _root["button_"+i].onPress = function() {
    getURL("http://www.oneurl.com"+_root["button_"+i].id);//this doesn't make valid urls
    };
    _root["button_"+i].play();
    }
    }
    };
    var sender = new LoadVars();
    sender.n = i;
    sender.f = floortodisplay.num;
    sender.sendAndLoad("elementtoshow.php", elementtodisplay, "post");



    maybe, for debugging purposes, you could check what your output says. For that you'd need to give the full url to "elementtoshow.php" so you can test local.

    Also check your getURL, i think you miss a slash..

    gparis

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