Professional Web Applications Themes

More efficient ActionScripting? - Macromedia Flash

Hey all, I'm using some code in one of my Flash movies that disables the hand cursor on all buttons (actually, they're movie clips). I'm currently using code like this: btnMyButton1.useHandCursor = false; btnMyButton2.useHandCursor = false; btnMyButton3.useHandCursor = false; .... But in a few cases I have almost 20 of these clips that I need to disable this for. Is there a more efficient way (or a way of using less code) to address objects like this in ActionScript or do I just have to put up with doing it this way? Thanks in advance, Nicko....

  1. #1

    Default More efficient ActionScripting?

    Hey all,

    I'm using some code in one of my Flash movies that disables the hand
    cursor on all buttons (actually, they're movie clips). I'm currently
    using code like this:

    btnMyButton1.useHandCursor = false;
    btnMyButton2.useHandCursor = false;
    btnMyButton3.useHandCursor = false;
    ....

    But in a few cases I have almost 20 of these clips that I need to
    disable this for. Is there a more efficient way (or a way of using less
    code) to address objects like this in ActionScript or do I just have to
    put up with doing it this way?

    Thanks in advance,
    Nicko.
    Nicholas Guest

  2. #2

    Default Re: More efficient ActionScripting?

    You should be able to do something like this:

    for (i:Number = 1; i <= 20; i++) {
    this["btnMyButton" + i].useHandCursor = false;
    }

    If your buttons are dynamically generated, then you might want to maintain a
    count of buttons and use that to set the limit for the loop instead.

    HTH,

    Max

    "Nicholas Sinclair" <net.au> wrote in message
    news:Tkiuf.167027$bigpond.net.au... 


    Max Guest

  3. #3

    Default Re: More efficient ActionScripting?

    >> btnMyButton1.useHandCursor = false; [/ref]
    ... [/ref]

    that is probably the most efficient already (in terms of how fast it works)
    ... might be slightly better as

    btnMyButton1.useHandCursor =
    btnMyButton2.useHandCursor =
    btnMyButton3.useHandCursor =
    ....
    btnMyButton20.useHandCursor = false;

    if you're worried about lines of code, then a loop as previous poster had
    (although syntax was missing the required 'var')

    for (var j : Number = 1; j <= 20; j++) {
    this["btnMyButton" + j].useHandCursor = false;
    }

    takes up less lines of code and file size, but would take a little longer to
    execute (if that is important)
    --
    Jeckyl


    Jeckyl Guest

  4. #4

    Default Re: More efficient ActionScripting?

    Yep...I usually end up forgetting the 'var' token and end up getting caught
    at run-time <g>.

    I hadn't run my code through the syntax check; thanks for clarifying it. I'd
    agree that a set of direct assignments would probably be the most efficient
    from a performance perspective. It wasn't clear from the original post
    whether he was looking for performance efficiency or lines of code
    efficiency. I opted for the lines of code...now he can choose.


    Regards,

    Max

    "Jeckyl" <com> wrote in message
    news:ahGuf.168001$bigpond.net.au... [/ref]
    > .. [/ref]
    >
    > that is probably the most efficient already (in terms of how fast it
    > works) .. might be slightly better as
    >
    > btnMyButton1.useHandCursor =
    > btnMyButton2.useHandCursor =
    > btnMyButton3.useHandCursor =
    > ...
    > btnMyButton20.useHandCursor = false;
    >
    > if you're worried about lines of code, then a loop as previous poster had
    > (although syntax was missing the required 'var')
    >
    > for (var j : Number = 1; j <= 20; j++) {
    > this["btnMyButton" + j].useHandCursor = false;
    > }
    >
    > takes up less lines of code and file size, but would take a little longer
    > to execute (if that is important)
    > --
    > Jeckyl
    >
    >[/ref]


    Max Guest

  5. #5

    Default Re: More efficient ActionScripting?

    On 12:35 PM Max Schneider, Image Innovation wrote: 

    Unfortunately, my example wasn't the greatest - they're not actually
    named sequentially unfortunately. I was just wondering if there was
    simply an easy way of saying: "Set useHandCursor = false for all movie
    clips"

    It doesn't seem like there is though... Thanks for everyone's reply
    anyway - greatly appreciated!

    Nicko.
    Nicko Guest

  6. #6

    Default Re: More efficient ActionScripting?

    there is .. but you didn't say you wanted that

    for (var name in this) {
    if (typeof this[name] == "movieclip") {
    this[name].useHandCursor = false;
    }
    }
    --
    Jeckyl


    Jeckyl Guest

  7. #7

    Default Re: More efficient ActionScripting?

    On 9:08 AM Jeckyl wrote: 

    Yeah I know - I do apologise and I'll be sure to clarify my questions
    next time before posting. Thanks for your reply, that's exactly what I'm
    after.
    Nicko Guest

Similar Threads

  1. Can this be done with actionscripting?
    By Travis Pupkin in forum Macromedia Flash
    Replies: 1
    Last Post: April 4th, 04:38 AM
  2. ActionScripting Width, Height, X, and Y ?
    By simsjr in forum Macromedia Flash Actionscript
    Replies: 3
    Last Post: March 4th, 04:37 PM
  3. actionscripting a .bmp
    By Swiggs in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 26th, 05:06 PM
  4. Need some ActionScripting help ...
    By Michael Stevens in forum Macromedia Flash
    Replies: 2
    Last Post: September 3rd, 05:58 PM

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
  •  

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