5 Replies Latest reply on Nov 22, 2006 9:14 PM by Newsgroup_User

    How would I write this in "modern" actionscript?

    asiabackpacker Level 1
      I am an old-school actionscripter. Got into AS way back when it first came out, haven't done it in a few years, and am trying to get back into it recently. As a result, I am sure that a lot of my syntax is out of date, like the below....

      This is a little function I wrote to fade in a movie clip. Can someone please tell me a more modern way to write this? I am sure my way-though it works-is totally outdated.

      Here is the function:

        • 1. Re: How would I write this in "modern" actionscript?
          Level 7
          First fix . .get rid of the evals...

          fadeVelocity = .07;
          fadeImage = function(clip) {
          clip._alpha += (clip.targetAlpha - clip._alpha) * _root.fadeVelocity;
          }

          > Inside my movie clip, I have the following code to call the function:

          _root.fadeImage (this); // not this._name, which really should have been
          this._target anyway

          onMouseDown = function () {
          targetAlpha = 100;
          }

          After that, its hard to tell because you code doesn'tseem to work anyway...
          why do you do the fade image AFTER you set the targetAlpha ... weird. And
          why do you only want ot call it one (surely it need to be called
          repeatedly).
          --
          Jeckyl


          • 2. Re: How would I write this in "modern" actionscript?
            asiabackpacker Level 1
            the part that calls the function is frame one in a looping movie clip-that's why it looks like i only call it once. It calls it every time the clip hits that frame. A retarded way to do things? Maybe... I just wanted the fade function to remain outside the clip, and globally accessible.

            For some reason jeckyl, I can't get it to work now the way you wrote it.

            If I put: trace(clip._width); inside the function, the result is "undefined"

            However, if I put trace(eval(clip)._width); I get the correct numerical value

            About the target alpha part: I am calling the function every time the clip hits this frame. When I set the targetAlpha to 100, that's when the image starts to fade in.

            OK, I know I'm probably borderline complete retard, and yes I will take a class (or at least read a book), but any help in the interim greatly appreciated! I've pasted your code exactly as is into my clip, but it doesn't work--maybe you can walk me through where each bit should go, so I can figure out if I have something in the wrong place??

            Thanks again!!!!!
            • 3. Re: How would I write this in "modern" actionscript?
              Level 7
              > For some reason jeckyl, I can't get it to work now the way you wrote it.

              Then you've probably done it wrong .. look at your calls to the function and
              ensure they are passing the clip itself (eg 'this') and not the NAME of the
              clip
              --
              Jeckyl


              • 4. Re: How would I write this in "modern" actionscript?
                asiabackpacker Level 1
                But don't I want to pass the name of the clip? Isn't that how I target the alpha? That's why at first I was using: this._name
                • 5. Re: How would I write this in "modern" actionscript?
                  Level 7
                  > But don't I want to pass the name of the clip?

                  no

                  > Isn't that how I target the alpha?

                  no

                  > That's why at first I was using: this._name

                  I know .. but that's not good

                  For a start if you ARE passing a name it should be _target (otherwise it
                  won't know where the clip lives)

                  But it is always better to pass (a reference to) the clip itself, rather
                  than its name. Its faster and safer.

                  Look at the code I corrected .. I explicitly said

                  _root.fadeImage (this); // not this._name, which really should have been
                  this._target anyway

                  --
                  Jeckyl