A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: functions...

  1. #1
    Junior Member
    Join Date
    Oct 2002
    Posts
    20

    functions...

    Hi all =)

    Ok. I have an mc, and 2 buttons. one to start it, one to stop it.. that all works fine

    i want another button, to work like an "on / off" button. When pressed the first time, the mc (instance name=cubes) fades into view, NOT playing. Then, when button is pressed again, the cubes fade out...

    i assume you do this using _alpha. ... but i've no idea how to actually make the function

    any help / advice, greatly appreciated.
    thanks

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    on your cubes clip:
    Code:
    onClipEvent(load){
    	fadespeed = 5
    }
    onClipEvent(enterFrame){
    	_visible = _alpha = Math.min(Math.max(0,_alpha+fadespeed),100)
    }
    on your button assuming it exists in the same timeline as your cubes:
    Code:
    on(release){
    	cubes.fadespeed = -cubes.fadespeed
    }
    fade speed starts out positive so it fades in (if its already full visible when it shows on screen). If you dont want to be able to see it to start, include in the load
    _visible = _alpha = 0
    and make the fadespeed negative
    max and min keep the alpha between 0 and 100 and setting the visible to the alpha hides the clip fully when it has an alpha of 0 (which on low color displays will still show)
    The button simply changes fade direction, either up or down.

  3. #3
    Junior Member
    Join Date
    Oct 2002
    Posts
    20
    Thanks... very nice code :P

    but there is a much simpler way to do it as some one has just shown me ...

    (the button is in diff. time line to the cubes)

    using a series of gotoandplay's, and stops, because the cubes is all a mc, and the buttons is a static 1 keyframe image, can be done like that. but thanks for your help any way.

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