I wanna use Use array to make my life easier...help

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default I wanna use Use array to make my life easier...help

    I'm trying to make my bottons to do bunch of same thing over and over, and I have 4 buttons, I want them to be in an Array, here's what I originally wrote in a old fashioin say

    ActionScript:
    btn1.onRelease = function(){
    trace("btn1 clicked");
    }
    btn2.onRelease = function(){
    trace("btn2 clicked");
    }
    btn3.onRelease = function(){
    trace("btn3 clicked");
    }
    btn4.onRelease = function(){
    trace("btn4 clicked");
    }




    but now I want to try to put it in array

    ActionScript:
    myBtns = [btn1, btn2, btn3, btn4];





    what I wanna do is to use this array and control my btns, like if myBtns[0] is click, the trace for btn and btn2-4 do somthing else, is there anyway that I can use if else statement to make one btn do one thing and other 3 btns do somthing else?..

    somthing like:
    ActionScript:
    myBtns.onRelease = function(){
    if(myBtn == 0){
    do this
    myBtn[1, 2, 3] do somthing else...
    }
    }





    I know this example sucks but I just want to learn how to do this..thanks a lot for your help..



    uncle_3than webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. MAKE MONEY EASIER
      Autor: Carlos Data: 17-10-05 Si dedicas 5 minutos a leer este articulo completo, te darás cuenta de que es algo verdaderamente ingenioso y que...
    2. AN EASIER WAY TO MAKE MONEY!! IT REALLY WORKS!!
      -- Ah An Easier Way To Make Money Post by Lisa Simmons July 6, 2005 @ 3:20 P.M. FIRST OF ALL, THIS IS NOT SPAM! THIS REALLY CAN MAKE YOU EASY...
    3. make array cell = array?
      I want to make a 2D array quickly $item = an array with the associative names , , etc... I want to do: $items_array = $item $i++
    4. Wanna buy a Cigar?....
      Is this legal???? Or is our legs being pulled. "Infidel Castro" <gimme_info@sympatico.ca> wrote in message...
    5. how to make a global scope array
      <20030725224852.1123.qmail@pb1.pair.com> Jack Lee: global $a;
  3. #2

    Default Re: I wanna use Use array to make my life easier...help

    something like this may work..

    for (var x in myBtns) {
    myBtns[x].onRelease = function() {
    trace(this+" clicked");
    }
    }

    the things that is making it tricky is that the script for the functions is
    different for each function. That's not something you can directly code ..
    that's why I changes your script a little so each button will use the same
    script.


    Jeckyl Guest

  4. #3

    Default Re: I wanna use Use array to make my life easier...help

    You can use prototype too!

    Button.prototype.onRelease = function() {
    trace(this._name + " clicked);
    }


    "uncle_3than" <webforumsuser@macromedia.com> escreveu na mensagem
    news:bvul9f$6lh$1@forums.macromedia.com...
    > I'm trying to make my bottons to do bunch of same thing over and over, and
    I have 4 buttons, I want them to be in an Array, here's what I originally
    wrote in a old fashioin say
    >
    > ActionScript:
    > btn1.onRelease = function(){
    > trace("btn1 clicked");
    > }
    > btn2.onRelease = function(){
    > trace("btn2 clicked");
    > }
    > btn3.onRelease = function(){
    > trace("btn3 clicked");
    > }
    > btn4.onRelease = function(){
    > trace("btn4 clicked");
    > }
    >
    >
    >
    >
    > but now I want to try to put it in array
    >
    > ActionScript:
    > myBtns = [btn1, btn2, btn3, btn4];
    >
    >
    >
    >
    >
    > what I wanna do is to use this array and control my btns, like if
    myBtns[0] is click, the trace for btn and btn2-4 do somthing else, is there
    anyway that I can use if else statement to make one btn do one thing and
    other 3 btns do somthing else?..
    >
    > somthing like:
    > ActionScript:
    > myBtns.onRelease = function(){
    > if(myBtn == 0){
    > do this
    > myBtn[1, 2, 3] do somthing else...
    > }
    > }
    >
    >
    >
    >
    >
    > I know this example sucks but I just want to learn how to do this..thanks
    a lot for your help..
    >
    >
    >

    Matheus Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139