How to duplicate button with the AS?

  • see i have this project where i need a number of buttons with the same function throughout the flash.

    i tried dragging them to the stage from the library, but the problem is i have to copy the AS over and over again, because i'm ASing on the main timeline, i have to give instance name to everyone one of them.

    is there an easier way to do it?

    i'm thinking script it using the linkage name rather than the instance name but i don't know how to do it, but that's just a thought.

    feel free to hammer me with other guidance and thanks


  • erm in the final work i sorta wanna attach the "buttons" into different movieclip, i'll show u guys a preview file i made, hope you guys would understand what i need :P

    i'm trying to duplicate the button without having to type the AS over and over again.


  • Always use attachMovie for large amounts of instances. Hand naming lots of instances is tedious and almost always unnecessary. mrwicked's code covers the basic principles you need to get started. In the case of his code, you'd have to make sure your button instance linkage is set to "btn".


  • erm, the real question is :

    the buttons i needed would be in a wide variety of positions and i wish i would be able to drag them on stage manually without retyping the AS over and over again, can you guys help me out on this?


  • Hmm so instead of having to write btn1.onrollover..btn2.onrollover..btn3..onroll...e ct, you want a function so that no matter what btn# it is, it moves your infobox over it on rollover and onrollout shoots it off the stage, correct?


  • hey thanks mrwicked, but i'm still a little lost, mostly due that i'm not familiar with the using of loops :P

    the buttons i needed would be in a wide variety of positions and i wish i would be able to drag them on stage manually, can you guys help me out on this? it would be cool if someone would be able to teach the them loops once and for all :ex:

    i'll try to play with the code you gave me but i'll check back this thread now and then, please help out !!!


  • you could put them all in a movieclip and use a for...in loop, search it in the Actionscript help


  • for (i = 0; i<5;i++) {
    var myBtn = this.attachMovie("btn", "btn"+i, this.getNextHighestDepth());
    myBtn._x = 100;
    myBtn._y = 100 + (myBtn._height + 2) * i;
    }







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about How to duplicate button with the AS? , Please add it free.