10 Replies Latest reply on Oct 20, 2006 10:33 PM by kglad

    Can't get _alpha to fade in and out on moving objects.

    binx4life
      I have some objects that are broken apart text on the main stage that move around randomly using the code below.

      I want it to include an _alpha change when it loads to go from 100% to 0% and back again in a loop. The effect I want is to have the moving text fade in and out and they move around. No button presses, just automaticly when the page loads. The code I have for the random movement works fine, I just can not get the _alpha to work the way I want, or at all.
        • 2. Can't get _alpha to fade in and out on moving objects.
          binx4life Level 1
          That worked great! Thank you!

          Now what would I have to change to have all the different MCs start at a different _alpha so they were not all at the same _alpha at the same time? Kinda so they were all at a different opacity at differrent times?

          Maybe it would be easier to have them start at a random _alpha and go to 100% from there, then loop?
          • 3. Re: Can't get _alpha to fade in and out on moving objects.
            Level 7

            "binx4life" <webforumsuser@macromedia.com> wrote in message
            news:ehbns9$p0o$1@forums.macromedia.com...
            >I have some objects that are broken apart text on the main stage that move
            > around randomly using the code below.
            >
            > I want it to include an _alpha change when it loads to go from 100% to 0%
            > and
            > back again in a loop. The effect I want is to have the moving text fade
            > in and
            > out and they move around. No button presses, just automaticly when the
            > page
            > loads. The code I have for the random movement works fine, I just can not
            > get
            > the _alpha to work the way I want, or at all.
            >
            > acceleration = 8
            > newpos = function () {
            > ranx = Math.round((Math.random ()*800));
            > rany = Math.round ((Math.random ()*380));
            > }
            > newpos();
            > this.onEnterFrame = function() {
            > this._x += ((ranx-this._x)/acceleration);
            > this._y += ((rany-this._y)/acceleration);
            > if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
            > newpos();
            > }
            > };
            >

            My solution is not nearly as clean as kglad's but here it is:

            Since this is not how I would have done this to start, I kind of made a duct
            tape solution by creating an empty movie clip to make use of it's own
            onEnterFrame.

            For starting each one with a random _alpha just add

            _alpha = Math.round(Math.random() * 100);

            /////////////////////////////////////////////////////////


            var acceleration:Number = 8
            newpos = function () {
            ranx = Math.round((Math.random ()*800));
            rany = Math.round ((Math.random ()*380));
            }


            this.onEnterFrame = function() {
            this._x += ((ranx-this._x)/acceleration);
            this._y += ((rany-this._y)/acceleration);
            if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
            newpos();
            }
            };

            var fadeAcceleration = 2;
            var fadeOut:Boolean = true;
            var destAlpha:Number = 0;
            var diff:Number = 100;

            var toggleControl_mc:MovieClip =
            this.createEmptyMovieClip("toggleControl_mc", 1);

            function toggleFade() {
            if (fadeOut) {
            destAlpha = 0;
            fadeOut = false;
            } else {
            destAlpha = 100;
            fadeOut = true;
            }
            toggleControl_mc.onEnterFrame = function() {
            diff = (_alpha - destAlpha) / fadeAcceleration;
            _alpha -= diff;
            if (Math.abs(diff) < 1) {
            _alpha = destAlpha;
            destAlpha = destAlpha == 100 ? 0 : 100;
            }
            }
            }

            newpos();
            toggleFade();


            • 4. Re: Can't get _alpha to fade in and out on moving objects.
              kglad Adobe Community Professional & MVP
              if you want them all to start with a random _alpha and all to fade-in, you could use:



              • 5. Re: Can't get _alpha to fade in and out on moving objects.
                Level 7

                "kglad" <webforumsuser@macromedia.com> wrote in message
                news:ehbpar$qg0$1@forums.macromedia.com...
                > try:
                >
                >
                >
                > acceleration = 8;
                > newpos = function () {
                > ranx = Math.round((Math.random()*800));
                > rany = Math.round((Math.random()*380));
                > };
                > newpos();
                > this.dec = 1;
                > this.onEnterFrame = function() {
                > if (this.dec) {
                > this._alpha -= 3;
                > if (this._alpha<=0) {
                > this.dec = 0;
                > }
                > }
                > if (!this.dec) {
                > this._alpha += 3;
                > if (this._alpha>=100) {
                > this.dec = 1;
                > }
                > }
                > this._x += ((ranx-this._x)/acceleration);
                > this._y += ((rany-this._y)/acceleration);
                > if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
                > newpos();
                > }
                > };
                >

                kglad,

                I see you post on here frequently (mostly helping the community) and was
                wondering two things.

                1. In the above code you produced for the OP, why do you have two if(s)
                instead of an if / else?
                2. If it is not too personal, what do you do for a living?

                Thanks for all of the contributions.


                • 6. Re: Can't get _alpha to fade in and out on moving objects.
                  kglad Adobe Community Professional & MVP
                  1. if/else would work, too. and even better would be just a plain "else".
                  2. i'm a pediatrician in orange, california.
                  • 7. Can't get _alpha to fade in and out on moving objects.
                    binx4life Level 1
                    I am using the code below, but they all still start the fading at the same time. Not sure what I am missing.