A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Script for button to fade in...

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    17

    Script for button to fade in...

    Hi, i am used to tweening to make buttons fade in, but how you do this using scripting that can be assigned to each button?

    Many thanks, Poly

  2. #2
    Senior Member Shnitzel's Avatar
    Join Date
    May 2007
    Location
    IL
    Posts
    130
    Fade out:
    instanceName._alpha -= 5; //Higher than 5 = faster, lower = slower.
    Fade in:
    instanceName._alpha += 5;

    _alpha controls the alpha (opacity) property of the object.

  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    17
    thanks, excuse my newbieness but what handler does this need to go in? i'm guessing its something like onClipEvent(load)... but keep getting errors

    also, how can a delay be assign to the fade in??

    many thanks

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    You would use a combination of setInterval (to provide the delay) and Tween in a function to complete full animation. The initial function would go under which ever element you want to cast the initial event.

    Everything else would fall under a separate method.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    Banned
    Join Date
    Nov 2002
    Posts
    60
    check here for some cool buttons
    http://flashden.net?ref=sixtyacura

  6. #6
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Sixtyacura, Are you helping with the issue, or just trying to advertise for your site?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  7. #7
    Junior Member
    Join Date
    Aug 2008
    Posts
    17
    my code for the movie (acting like a button) is
    onClipEvent (load) {
    MovieClip.prototype.Increment = function(maxAlpha, speed) {
    this.onEnterFrame = function() {
    this._alpha += speed;
    if (this._alpha>=maxAlpha) {
    this._alpha = maxAlpha;
    delete this.onEnterFrame;
    }
    };
    };
    with ("thumb0") {
    _alpha = 0;
    Increment(60,8);}
    }

    I've tried adding the setInterval command at the end but no luck
    where would the setInterval need to go?? and what is the functionName it requires? i'm guessing it would be 'Increment'.

  8. #8
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    Arrow Using SetInterval

    First, I'm going to assume you've created a new instance of the Increment class, otherwise your button wouldn't fade in. For more info on prototypes try here

    I changed the code a little which is excluding your prototype. Modify my version to work for your situation.

    Code:
    //On Main timeline not within a button or clip
    
    var intervalID:Number;
    
    function incrementMe(obj, max, speed)
    {
       obj._alpha += speed;
        if (obj._alpha>=maxAlpha) {
             obj._alpha = maxAlpha;
             clearInterval(intervalID);
        }
    }
    
    //When the button is released, then it will start the entire cycle.
    thumb0.onRelease = function()
    {
        clearInterval(intervalID);
        this._alpha = 0;
        intervalID = setInterval(incrementMe, 100, this, 60, 8);
    }
    I didn't instantiate my button with the prototype, so I excluded it. I have a function that does nothing but increases the alpha of a specific obj to the maximum available for that object. This code can be added to the class used when the button was instantiate, and the name of the function would be called then (ie. thumb0.increaseMe().

    With in my if state of the increase function, I have a clearInterval. This stops the repeating call to incrementMe.

    I place the calling function within the button. When the button is released, it changes it alpha to zero, and start the interval calling the incrementMe function, at 100 milliseconds intervals and passing the other necessary parameters (whos calling, max alpha, and speed).

    Does that help?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this Thread

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