A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: using actionscript to fade stuff

  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    32

    using actionscript to fade stuff

    So, I'm trying to use actionscript more and more instead of using built in easy tweens...

    I have a site I am building, its something like a picture gallery. I want the user to click on a button and have the image showing fade out and have the new one fade in.

    I figured that I would need to call the new image by using what is, essentially, an empty movie clip. I cant figure out how to get the transparency to work for me without actually taking each and every image and tweening them individually. Is there a way to just write actionscript with a function that can be applied to each image, whther it is a swf or a jpg when it is called that will give the fade in/out effect?

    Like I said, right now I have the buttons calling the images, but I would like to use actionscript so all I have to do is add images without having to edit each image.
    Please help if u can
    thanks!
    D

  2. #2
    Junior Member
    Join Date
    Dec 2004
    Posts
    22
    you'd want to do something like this:

    code:

    function fadeOut(clip_mc)
    {
    clip_mc.onEnterFrame = function()
    {
    this._alpha -= 10;

    if(this._alpha <= 0)
    {
    this._alpha = 0;
    delete this.onEnterFrame;
    }
    }
    }


  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    There are a lot of ways to do that. Depending on your structure and what effect you exactly want. Here is a small example:
    http://www.flashkit.com/board/showth...hreadid=603858

    A quick search in this forum will yield more results.

    gparis

  4. #4
    Member
    Join Date
    Jun 2004
    Posts
    32
    thanks guys, i am still a little unclear though. Where would this actionscript go?

    here is the only code i have right now - on a button that loads an image. I thought that if an image was loaded into a movie clip that it was supposed to take on that mc's attributes. But it doesnt appear to be working that way for me.

    on (release) {
    loadMovie("image1_mc.swf",6);

    }

  5. #5
    did0bib chero's Avatar
    Join Date
    Jun 2004
    Location
    in a bar, under the sea
    Posts
    751
    I used this script to create a fading images slideshow, you might find it useful - it has three buttons plus one fade in and one fade out function, used in setInterval. Also, you should place your movie clips each in its own layer, one atop another, and use this script in the main timeline:
    code:

    var mclipz = new Array (m1_mc, m2_mc, m3_mc, m4_mc);
    var current = 0;
    var fadingAction:Number;

    plus_mc.onRelease = function() {
    clearInterval (fadingAction);
    fadingAction = setInterval (fadeOut, 30, mclipz[current]);
    if (current >= mclipz.length) {
    current = mclipz.length;
    }
    };
    minus_mc.onRelease = function() {
    clearInterval (fadingAction);
    fadingAction = setInterval (fadeIn, 30, mclipz[current]);
    if (current <=0) {
    current = 0;
    }
    };
    reset_mc.onRelease = function() {
    for (i = 0; i <= mclipz.length; i++) {
    mclipz[i]._alpha = 100;
    current = 0;
    }
    };
    function fadeOut(mcPlanet) {
    mcPlanet._alpha -= 5;
    if (mcPlanet._alpha <= 0) {
    clearInterval (fadingAction);
    current++;
    }
    updateAfterEvent;
    }
    function fadeIn (mcPlanet) {
    mcPlanet._alpha +=5
    if (mcPlanet._alpha >= 100) {
    clearInterval (fadingAction);
    current--;
    }
    updateAfterEvent;
    }


    I've also included my original fla (I used planets in slideshow, so instance & variable names are different, but the script is one & the same)
    Attached Files Attached Files

  6. #6
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    on (release) {
    loadMovie("image1_mc.swf",6);
    }

    That's not loading the movie in a container movie clip but on level 6 of your main movie.

  7. #7
    Member
    Join Date
    Jun 2004
    Posts
    32
    oldnewbie - oops, i was playing around with options and actually pasted the wrong version of my script there.

    chero - thanks, I'm going to give this a shot. I'm new to AS so it'll take me a minute.
    Thanks
    D

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