13 Replies Latest reply on May 22, 2017 11:59 AM by Focusfilm.at

    Pass Instance Name into function

    Focusfilm.at Level 1

      Hi Everyone, sorry for posting so many beginners questions in the last few days...,

       

      Whats wrong with this code?

       

      function fadeOUT(e:String):void

      {

       

        this[e].addEventListener(Event.ENTER_FRAME, fadeOUT);

        this[e].alpha -= 0.1;

        if (this[e].alpha <= 0)

        {

             this[e].removeEventListener(Event.ENTER_FRAME, fadeOUT);

             trace("fire")

        }

      }

      fadeOUT("McInstanceName");

       

      If the code is like this i get an "

      TypeError: Error #1010: A term is undefined and has no properties.

        at Test87_fla::MainTimeline/fadeOUT()"

       

      Here is the Part i don't understand: The code does not produce Errors if i do one of the following:

      • Change this[e].alpha -= 0.1; to this[e].alpha -= 1;
      • Comment out this[e].addEventListener(Event.ENTER_FRAME, fadeOUT);

       

      Is there maybe another way to pass a movieClip into a function?

      I would appreciate any help, thanks