SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: actionScript ?

  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    actionScript ?

    the code below duplicates a MovieClip 15 times. The new movie clips have the name msg1,msg2,msg3 and so on asigned to them. These new MovieClips have btns in them. How would I attach an action to each of these new buttons via code?


    var xpos = _root.msgbox._x;
    var xstep = 22;
    var stack = 7;
    for (var i = 0; i<16; i++) {
    duplicateMovieClip(_root.msgbox, "msg"+i, 1-i)
    ypos = _root["msg"+i]._y
    _root["msg"+i]._x = xpos;
    _root["msg"+i]._y = ypos;
    xpos += xstep;
    }

  2. #2
    Outsource Web Design featuredhost's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Flash 5 or MX ?

  3. #3
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MXXXXXXX

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if it was say onRelease

    Code:
    var xpos = _root.msgbox._x;
    var xstep = 22;
    var stack = 7;
    for (var i = 0; i<16; i++) {
      duplicateMovieClip(_root.msgbox, "msg"+i, 1-i)
      ypos = _root["msg"+i]._y
      _root["msg"+i]._x = xpos;
      _root["msg"+i]._y = ypos;
      _root["msg"+i].buttonName.onRelease = function() {
       //do something
      }
      xpos += xstep;
    }
    However since you are using duplicateMovieClip, I assume you have one already made with a button in it. You might want to think about making the function inside the mc to be duplicated and then chaning something about how it works with a variable.

    Like if the function in the clip was

    Code:
    var what = "";
    this.buttonInstance.onRelease = function() {
      _root.gotoAndPlay(what);
    }
    Then in your code
    Code:
    var xpos = _root.msgbox._x;
    var xstep = 22;
    var stack = 7;
    for (var i = 0; i<16; i++) {
      duplicateMovieClip(_root.msgbox, "msg"+i, 1-i)
      ypos = _root["msg"+i]._y
      _root["msg"+i]._x = xpos;
      _root["msg"+i]._y = ypos;
      _root["msg"+i].what = "home";
      xpos += xstep;
    }

  5. #5
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, good ideas, ill try them later, thx

  6. #6
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh man close!

    my code now:

    stop();
    loadVariables("messages.txt", "msgholder");
    //---------------------------------------
    var xpos = _root.msgbox._x;
    var xstep = 22;
    var stack = 7;
    for (var i = 0; i<16; i++) {
    duplicateMovieClip(_root.msgbox, "msgbtn"+i, 1-i)
    ypos = _root["msgbtn"+i]._y
    _root["msgbtn"+i]._x = xpos;
    _root["msgbtn"+i]._y = ypos;
    _root["msgbtn"+i].msgtxt = _root.msgholder["msg"+i];

    xpos += xstep;
    }

    THE QUESTION
    notice that I'm loading Variables into a MC called "msgholder" these variables will have the names msg1, msg2 and so on.

    so how do I set that in this line of code: _root["msgbtn"+i].msgtxt = _root.msgholder["msg"+i];

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [cpde]
    loadVariables("messages.txt", "msgholder");
    [/code]
    What does that text file look like?

    Also are you using Flash MX or Flash 5?

    One more thing if te code you posted is exactly what you have in your movie we have a problem. You cannot start using variables loaded using loadVariables until they have been loaded. I would put the loadVariables line in one frame with a stop and then use a onClipEvent(data) handler on the msgholder clip with code to advance to the next frmae when the variables have loaded.

    Frame 1:
    Code:
    loadVariables("messages.txt", "msgholder");
    stop();
    Frame 2:
    Code:
    var xpos = _root.msgbox._x;
    var xstep = 22;
    var stack = 7;
    for (var i = 0; i<16; i++) {
    duplicateMovieClip(_root.msgbox, "msgbtn"+i, 1-i)
    ypos = _root["msgbtn"+i]._y
    _root["msgbtn"+i]._x = xpos;
    _root["msgbtn"+i]._y = ypos;
    _root["msgbtn"+i].msgtxt = _root.msgholder["msg"+i];
    
    xpos += xstep;
    }
    stop();

    On the msgholder instance
    Code:
    onClipEvent(data) {
      _root.gotoAndPlay(2);
    }

  8. #8
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u got it. nice work. cheers


Bookmarks

Posting Permissions

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