Skip to main content
Participating Frequently
May 2, 2008
Question

remove code

  • May 2, 2008
  • 5 replies
  • 620 views
The movieclips are removed with this code

function retractMenu(event:Event):void{
for(var a = 0; a < menuButs.length; a++){
this.removeChild(menuButs);
menuButs
= null;
}
}
This topic has been closed for replies.

5 replies

Ned Murphy
Legend
May 2, 2008
Put a trace after the loop of the clearMenuButs() function to see what's inside the menuButs array [ trace(menuButs); ]... maybe put two traces, one before and one after the newly installed menuButs.length = 0;

You could also check to see what's in the menuButs array when you are pushing things into it.
kglad
Community Expert
Community Expert
May 2, 2008
i didn't sign on to debug your entire application. i only asked for the mc_tab listener function. if that function calls another relevant function, posting that too would be helpful. but not many of want to go through your entire code.
kglad
Community Expert
Community Expert
May 2, 2008
show your listener function for tab_mc using the attach code option.
Participating Frequently
May 2, 2008
package com{
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.events.*;
import flash.utils.*;
public class documentClass extends MovieClip{

public var container:MovieClip;
public var menuOpen:Boolean = false;
public var butNames:Array = ["ABOUT","WORK","LAB","CONTACT"];
public var menuButs:Array = new Array();
public var counter:Number = -1;
public var counter2:Number = 4;
public var menuclip:MovieClip;

public function documentClass(){


init();
}
public function init():void{
var theMask:MovieClip = new MovieClip();
addChild(theMask);
for(var a = 0 ; a <20; a++){
var redball = new circle_mc();
theMask.addChild(redball);
logo_mc.mask = theMask;
redball.scaleX = 1;
redball.scaleY = 1;
redball.x = Math.random() * 420;
redball.y = Math.random() * 248;
var launch1 = new Tween( redball, "scaleX", Strong.easeIn, redball.scaleX, 15, 0.5, true );
var launch2 = new Tween( redball, "scaleY", Strong.easeIn, redball.scaleY, 15, 0.5, true );

}
loadMenutab();
}
public function loadMenutab(){
var menutab = new menutab_mc();
addChild(menutab);
menutab.x = -25.0;
menutab.y = 230.0;
menutab.buttonMode = true;

var myTween:Tween = new Tween(menutab, "x", Elastic.easeOut, -25, 0, 3, true);
menutab.addEventListener(MouseEvent.MOUSE_DOWN,menuCall);
container = new MovieClip();
addChild(container);

}
function menuCall(e:Event):void{
if(getMenuOpen() == false){
activateMenu();
}else if(getMenuOpen() == true){
deactivateMenu();
}

}
function activateMenu(){
setMenuOpen(true);
//counter = counter - 1;
var sender = setInterval(launch,200);
function launch(){
counter++;
//trace(counter + " activate");
menuclip = new menuBtn();
container.addChild(menuclip);
menuclip.x = 65.0 + ( counter * 166);
menuclip.y = 230.0;
menuclip.buttonMode = true;
menuclip.scaleX = 0;
//menuclip.label.text = butNames[counter];
menuButs.push(menuclip);
var myTween:Tween = new Tween(menuclip, "scaleX", Elastic.easeOut, 0, 1.0, 1.5, true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, activateButs);

if(counter == 3){
clearInterval(sender);
counter = -1;


}
}
}
function setMenuOpen(tabvalue:Boolean):void{
menuOpen = tabvalue;

}
function getMenuOpen(){
return menuOpen;

}
function deactivateMenu(){
//counter = counter + 1
setMenuOpen(false);

var sender = setInterval(retract,200);
function retract(){

counter--;
trace(counter + " deactivate");
var target = menuButs[counter];
trace(target);
var myTween2:Tween = new Tween(target, "scaleX", Elastic.easeOut, 1.0,0, 0.7, true);
myTween2.addEventListener(TweenEvent.MOTION_FINISH, activateButs);
if(counter == 0){
clearInterval(sender);
//counter2 = 4;
clearMenuButs();
}
//clearMenuButs();
//clearInterval(sender);
}
}
function activateButs(event:TweenEvent):void {
for(var a = 0; a < menuButs.length; a++){
menuButs.addEventListener(MouseEvent.ROLL_OVER,menuRollOver);
menuButs
.addEventListener(MouseEvent.ROLL_OUT,menuRollOut);
menuButs.buttonMode = true;
}
}


function menuRollOver(e:Event){

e.target.gotoAndStop(5);

}
function menuRollOut(e:Event){

e.target.gotoAndStop(1);
}
function clearMenuButs():void{
function retractMenu(event:Event):void{
for(var a = 0; a < menuButs.length; a++){
this.removeChild(menuButs
);
}
menuButs.length=0;

}
}
}
kglad
Community Expert
Community Expert
May 2, 2008
are you adding children before your 2nd call?
Participating Frequently
May 2, 2008
I am trying to use the movieclip called "tab_mc" as a toggle button. click it to add 4 movieclips to the stage, click it again to remove them. works once then fails.
Participating Frequently
May 2, 2008
Unfortunately it is still generating the same error the second time around

TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/removeChild()
at test2_fla::MainTimeline/retractMenu()