Make multiple objects within a movieclip disappear at once - actionscript-3

I have multiple buttons within a movieclip "mc_circlebtn". I want to make all of them disappear at once with actionscript 3. How can I do it? Would really appreciate it if I could get some fast responses. Thank you.

I am not sure what you are trying, but maybe this is what you need, run this code when you want to remove buttons:
for (var i:int = mc_circlebtn.numChildren-1; i >= 0; i--)
{
mc_circlebtn.removeChildAt(i);
}

Related

How to let an object appear in actionscript

I have an animation that may stop at 2 points depending on what the user fills in, if the animation stops at one of the two frames an objects has to apear and have to disappear if the user continues with playing the animation again. Can someone tell me how I can let object appear if the animation stops at a certain frame?
Do I need something like this? I have very little experience so please help!
star_mc._alpha = 0; star_mc.onEnterFrame = function(){ if(this._alpha < 100){ this._alpha = this._alpha + 5; }}
The code looks ok.... try it... just put it in the right place!
It's hard to tell where because I don't know how your animation built!!

Flash AS3 Remove Clip, reorder other items

I have a scrollpane to which I add movieclips to. I am using it a an online users list. It works well so far but now I have run into a problem. I am able to remove the movieclips I want easily enough using removechild, but when I remove it there is only a blank space where the removed clip was. So I need to know how to have the scrollpane refresh somehow and move the clips below that one removed up. How can I do this?
I have tried invalidate, refreshPane, update, etc. Maybe I didnt have them in the correct order or something, but how can this be done?
If the answer is complex, could an example be provided please? Im really not good enough with as3 just yet to code an entire algorithm to get the number of children, remove them all, readding them, etc.
Any help please?
Just a variation, but saves the -1, simply rearrange such as:
lstOnline.removeChild(lstOnline.getChildByName("NAMEHERE"));
var numleft:Number = lstOnline.numChildren;
for(var i = 0; i < numleft - 1; i++) {
lstOnline.getChildAt(i).y = i*60;
}
Guess I was a little better than I thought. In case anyone else faces this problem, the solution I found was the following:
var numleft:Number = lstOnline.numChildren;
lstOnline.removeChild(lstOnline.getChildByName("NAMEHERE"));
for(var i = 0; i < numleft - 1; i++) {
lstOnline.getChildAt(i).y = i*60;
}
lstOnline is the name of the ScrollPane and in my case 60 is the height of the added movieclips.

Masking Many Objects With 1 Mask Using `getChildAt(i).mask` Not Working

I am attempting to apply a mask to all objects on the stage except for a couple. There are a lot of different objects, and the amount of them will change in the future, so I want the masking to be done dynamically.
I wrote this code:
var i;
for (i = 0; i < this.numChildren; i++) {
if (this.getChildAt(i).name!="stage_kelp_bg" && this.getChildAt(i).name!="magnifier_mask") {
this.getChildAt(i).mask = this.magnifier_mask;
}
}
The above code is inside the document class's constructor method. Simply stating something like:
this.stage_kelp.mask = this.magnifier_mask;
works flawlessly, but only for that one object. Any idea what's wrong?
No errors are thrown, the objects just simply don't get masked.
Further research shows me that I cannot apply 1 mask to multiple objects. I have to have a mask for each object, or put all the objects into one container and mask that container.
Apparently you can use a layer to mask multiple objects on the timeline, but you can't do it programmatically without adding all the objects to one container. Unfortunately I can't do this without re-coding the entire application, so I will be using the timeline to mask things.
I would suggest you to better move all the movieclips to be masked in a single movieclip. This would be easier, if it's feasible in your case.
How about for each
for (var mc:movieClicp in this){
mc.mask=mask_}

Flex AS3 : Find and remove elements from container of certain class

How can I remove only every image found in a Bordercontainer which also holds Textinputs and Buttons ?
i tried:
for(var i:int=0;i<container.numElements;i++){
if(container.getElementAt(i) is Image){
container.removeElementAt(i);}
}
But as expected this loop does not fully work since the numElements changes which means that not all Images get removed.
I know there is some simple trick to this...but I cant think of it right now...Please help
As commenters have suggested, it seems like looping backwards would be the way to do it. I'd try something like this:
var totalElements : int = container.numElements;
for(var i:int=totalElements-1;i>=0;i--){
if(container.getElementAt(i) is Image){
container.removeElementAt(i);
}
}
By storing the numElements in a variable before starting the loop, you can be sure that the value will not change while processing the loop. Since your going backwards, you don't have to worry about the child index changing.
A second option would be to queue up the image instances in one loop and remove them in a second loop using the removeElement method. I suspect the two loop method will have significantly worse performance.
Looping backwards would be 1 way to do this.
Another would be
for(var i:int=0; i<container.numElements; i++){
if(container.getElementAt(i) is Image){
container.removeElementAt(i);
i--; //This nullifies the effect of removing an element
}
}

Random position without overlapping

How to stop MCs from overlapping each other?
private function loadWishes():void {
for (i; i<myXMLList.length(); i++) {
cBox=new MovieClip();
checkOverlap(cBox);
addChild(cBox);
commentArray.push(cBox);
}
}
private function checkOverlap(wishB:MovieClip) {
wishB.x=Math.random()*stage.stageWidth;
wishB.y=Math.random()*stage.stageHeight;
for (var i:uint=0; i<commentArray.length; i++) {
if (wishB.hitTestObject(commentArray[i])) {
checkOverlap(wishB);
return false;
}
trace(commentArray.length);
}
}
This doesn't seems to be working cause the amount of it checking whether MC is overlapping is about the amount of MC on stage. how to make it keep checking till everything's fine?
The code you have here should work in general for preventing overlapping (though you should be careful - in a worst-case scenario this code might loop infinitely if the clips are too big or the stage is too small).
However, your problem is that you're calling this code on newly-created MovieClip objects, which are empty - so they can never overlap. Presumably you're adding in some child contents to the clips later, and at that point they overlap. So the fix is, you should populate the clips first, before checking if they overlap, or alternately, if you know the size of the clips, then instead of calling hitTestObject you could manually check whether the clip's position is too close to other clips.