A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Change Opacity over Time

  1. #1
    Junior Member
    Join Date
    Jun 2006

    Change Opacity over Time

    Hi guys, i'm looking for AS code which will change the opacity of a movie clip by +X over Y time and not go beyone a certain opacity level. I know that that the getTimer() function will need to be used but i'm at a loss as to how to devlop it. I couldn't find the answer on Google.

    Any help is appriciated.

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    New Hope, PA
    By this I assume you mean alpha. You can do that with the Tween class.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    London, UK
    suppose you have:

    instance ball1_mc which u want to go to opacity 30 in 5 secs
    instance ball2_mc which u want to go to opacity 100 in 15 secs

    then use

    changeOpacity(ball1_mc, 30, 5);
    changeOpacity(ball2_mc, 100, 15);
    function changeOpacity(movie:MovieClip, opacityFinal:Number, secs:Number):Void {
    	if(movie._alpha < opacityFinal){movie.increase = true;}else{movie.increase = false;}
    	movie.opacityChange = Math.abs(movie._alpha - opacityFinal);
    	movie.opacityRate = 0.4 * movie.opacityChange/secs; //opacity rate change per 0.4 sec
    	movie.nChange = setInterval(changer, 0.4 * 1000, movie);
    	function changer(movie:MovieClip):Void {
    			movie._alpha += movie.opacityRate;
    			if (movie._alpha >= opacityFinal) {
    			movie._alpha -= movie.opacityRate;
    			if (movie._alpha <= opacityFinal) {
    P.S this is not 100% accurate e.g 15 secs may take 15.5 seconds and 30 opacity may end up being 29.4 opacity

    eidt: Just saw kotex's reply (ive never used the tween class) damn u can do that with it? lol
    Last edited by silentweed; 06-22-2006 at 12:47 PM.
    Flashmatics | Flashmatics Library (free downloads)
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    Flash Certified Developer

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