5 Replies Latest reply on Dec 22, 2006 9:21 AM by crazyjoemilan

    Scoping & filter problem

    crazyjoemilan Level 2
      So here's the idea. RIght now, I'd like to be able to have my mc "mainPiece" blur in and out using the flash.filters in AS. I think my problem is scoping. Before I turned it into a function, it was working fine as a static filter (non-animated). However, I'd like to be able to control that. Please take a look at the code and tell me what I can do about it.

      theInit = 1;
      for (i=1; i<=3; i++) {
      this["myBlur"+i] = new flash.filters.BlurFilter(i*4, i*4, 1);
      }
      function fadeBlur() {
      var myTempFilters:Array = mainPiece.filters;
      myTempFilters[0] = (this["myBlur"+theInit]);
      mainPiece.filters = myTempFilters;
      if (theInit == 3) {
      theInit--;
      } else {
      theInit++;
      }
      }
      setInterval(fadeBlur, 20);
        • 1. Re: Scoping &amp; filter problem
          crazyjoemilan Level 2
          After posting I realize I have some problems in my thinking anyway (namely the if else statement at the bottom). Those are pretty easy to solve, so ignore those. I need the top part to work, and I cannot do it alone captain.
          • 2. Re: Scoping &amp; filter problem
            PabIo
            As you said, your problem here is the scope, I pasted your code directly into the frame 1 of the main timeline (_root) and fixed the scopes ('mainPiece' is placed in the same frame).

            This should work (anyway, it should be much better not to use absolute paths and also to modify directly the filters of the mainPiece, instead of assigning a new one in each iteration):




            • 3. Re: Scoping &amp; filter problem
              crazyjoemilan Level 2
              I posted a reply to this, but apparently I got logged out somehow.

              Thank you for taking the time! I need it to be a relative path, sadly, since the piece will be loading in different levels. But I fail at scoping in functions without using _root. Can you help me out that way?
              • 4. Re: Scoping &amp; filter problem
                PabIo Level 1
                I dont know how you exactly want to use the function, but if you want to use relative scoping, I think the best you can do is to pass the function a pointer to the scope from where it was called (I'm typing this very fast, I have a really busy day!! :( so it's only a random example, you can apply it to your function...)


                var text:String = "hola"

                function traceText(myScope) {
                trace (myScope.text);
                }

                traceText(this);


                Use the 'myScope' variable to reference, whithin the function, any relative path to the object from which the function was called:

                myScope.anyChildren...
                myScope._parent._parent._parent.... (and so on until Adam and Eve)

                Ah! and if you want to use the "setInterval" function, also you can pass parameters to the function you are setting the interval for:

                setInterval(function, interval, param1, param2, ... etc)

                in this eample:

                setInterval (traceText, 1000, this);

                I hope this will help!
                • 5. Re: Scoping &amp; filter problem
                  crazyjoemilan Level 2
                  Use the 'myScope' variable to reference, whithin the function, any relative path to the object from which the function was called:

                  woohoo! thanks. I'm also pretty busy on a project, but I think this is what I was looking for. Thanks for taking the time. Happy Holidays.