A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Dynamically Removing Filters

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Location
    the Internet
    Posts
    9

    Dynamically Removing Filters

    Basically, the effect I'm going for is, you click on a button that calls an mc to the stage and blurs everything below it. When you click another button (that was also called), that mc (and button) is removed, as well as the blur filter.

    This is the code I have. (Also, just ignore my stupid function names. I pretty much just name them after the next word I hear in the song I'm listening to :\)

    Code:
    hint.addEventListener(MouseEvent.CLICK,manipulation);
    function manipulation(event:MouseEvent){
    	this.addChild(newHint);
    	newHint.x = 121;
    	newHint.y = 78;
    	
    	this.addChild(newX);
    	newX.x = 350.9;
    	newX.y = 100.0;
    
    	var i:int = this.numChildren - 5;
    	while(i > 0){
                 i--;
        
                 this.getChildAt(i).filters = BLUR;
    	} 
    	
    	newX.addEventListener(MouseEvent.CLICK,traumst);
    	function traumst(event:MouseEvent){
    		removeChild(newHint);
    		removeChild(newX);
    		var i:int = this.numChildren - 5;
    		while(i > 0){
    		     i--;
    		
    		     this.getChildAt(i).filters = [];
    		} 
    	} 
    }
    Everything works perfectly except for
    Code:
    var i:int = this.numChildren - 5;
    while(i > 0){
    i--;
    		
    this.getChildAt(i).filters = [];
    }
    and I don't have any compiler errors, the stuff just simply won't unblur. Does anyone have any idea how to do this?

  2. #2
    1) try tracing i before that little loop just to make sure that it is a positive number
    2) this.getChildAt(i) will return a display object, not sure but you might need to cast that as a sprite or movieclip to access the filters array

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Location
    the Internet
    Posts
    9
    Traced i, it is a positive number.
    And, well, if
    Code:
    var i:int = this.numChildren - 5;
    while(i > 0){
         i--;
    		
         this.getChildAt(i).filters = BLUR;
    }
    works, why wouldn't the other one? Either way, how would I cast it as a movieclip or sprite?

  4. #4
    what does this do for you?
    this.getChildAt(i).filters = BLUR;

    are you setting BLUR to something in code that you aren't displaying? it should be an array. I would do something like Sprite(this.getChildAt(i)).filters = [];

  5. #5
    Junior Member
    Join Date
    Aug 2009
    Location
    the Internet
    Posts
    9
    BLUR is an array, yeah.
    Code:
    var BLUR:Array = [new BlurFilter(16, 16, 1)];
    And this.getChildAt(i).filters = BLUR; works perfectly, blurring everything below the specified Z-Index. I don't understand why the other won't work. I tried Sprite(this.getChildAt(i)).filters = []; and it didn't do anything.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Don't use magic numbers, like 5, to have semantic meaning.

    In the first case, when you are adding the filters, you have just added newHint and newX, so numChildren is 2 more than in the second case when you have just removed them.

    You should also define traumst outside of manipulation, but that is not causing an error here.
    Last edited by 5TonsOfFlax; 08-03-2011 at 01:08 PM.

  7. #7
    Junior Member
    Join Date
    Aug 2009
    Location
    the Internet
    Posts
    9
    True enough... I changed the number, but still isn't working.

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