-
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?
-
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
-
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?
-
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 = [];
-
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.
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|