A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: why does this work?

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326

    why does this work?

    I know that this works:
    Code:
    clip.onPress = clip.onRelease = function () {
    	trace("yeah");
    };
    (both when pressed and released a trace occurs)
    But I can't find anything about it in the help file WHY this is correct and why it works. Can someone lead me to the page where it says this is correct syntax for combining multiple event handlers into one? I can only find this one:
    on (press, release) ...

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    156
    Thats correct, on (press, release) is the old way

    Im not sure what as3 is, anyone want to chime in?

  3. #3
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326
    I'm using Flash 8 and this works just as well. I don't get any error messages in the output window or while autoformatting. I can understand the logic behind it somewhat, but can't find anything in the help files that this kind of syntax is ok. Does is say anywhere this kind of format is acceptable?

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  4. #4
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    This doesn't need to be documented as being correct, it just is.

    You can do multiple assignments on one line...
    PHP Code:
    "abcd all have the same value"
    "abcd all have the same value"
    "abcd all have the same value"
    "abcd all have the same value" 
    ... can be rewritten as...
    PHP Code:
    "abcd all have the same value"
    d
    c

    ... and is the same as...
    PHP Code:
    "abcd all have the same value"
    Whenever you make an assignment it is the value of that assignment that is returned. e.g. If you trace(d = "abcd all have the same value"); then you see that the value of d is traced out ("abcd all have the same value"). And so you can see how this multiple assignment kind of propagates from right to left.

    In other words it's just a short hand way of assigning the onPress and onRelease function to the same function and at the same time.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

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