Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

movie_clip.removeMovieClip() is not working

Status
Not open for further replies.

okiiyama

IS-IT--Management
Jan 3, 2003
269
US
Flash is becoming irritating...

All of my movieclips were created entirely in Actionscript except for one which has a nested scrollpane. If I delete the nested scrollpane mc from the library, I can use mc.removeMovieClip(), but with the nested scrollpane MC at least on the stage and I think the scrollpane just needs to be in the library, the movieclips I am trying to remove are not being removed. I'm not trying to remove the nested scrollpane MC. So, what do I need to do to be able to use removeMovieClip() again? The easiest would be to not use a scrollpane, but I would like to it would make life easier.

Any help would be great!

Thanks.
 
Thank you. What is the difference in using unloadMovie and removeMovieClip? There is something that seems to linger though with unloadMovie. Should I unload each child movie clip?

I've included my code which Both pieces of code are in the first frame. In my library I have a movie clip called content_window_mc which has a scrollpane nested in it. You'll see a reference to it and maybe a couple calls to functions I added to content_window_mc. The references to content_window_mc is in the function "menu_item_select()".

Here is the main code which creates the menu groups, each menu item, and when menu items are pressed, the loading and unloading of submenus
Code:
var menu_dark_grad_color = 0x660000;
var menu_light_grad_color = 0xCC0000;
var menu_border_color = 0x000000;
var menu_item_min_width = 180;
var menu_item_height = 20;
var menu_item_bg_id = 1;
var menu_group_id = 1;

var content_x = 8;
var content_y = 140;

var content_width = 500;
var content_height = 300;

var ALPHA_FLOOR = 40;
var ALPHA_CEILING = 100;

//Each item in mainmenuArr can have a submenu
//If it has a submenu, the submenu must use a specific
//naming convention as seen below ex "LEADERSHIP_submenu"
//If there is not a submenu for a menu item that means
//there that menu item has content, so a process needs to
//be written to create a content_window -- Not done yet.
var mainmenuArr:Array = new Array();
mainmenuArr.push("  LEADERSHIP");
mainmenuArr.push("  MARKETING ADVANTAGE");
mainmenuArr.push("  TECHNOLOGY");
mainmenuArr.push("  TRAINING");
mainmenuArr.push("  SUPPORT");
mainmenuArr.push("  BENEFITS");

var LEADERSHIP_submenu:Array = new Array();
LEADERSHIP_submenu.push("  LOCAL LEADERSHIP");
LEADERSHIP_submenu.push("  NATIONAL LEADERSHIP");
LEADERSHIP_submenu.push("  SUPERIOR INNOVATIONS");

var MARKETINGADVANTAGE_submenu:Array = new Array();
MARKETINGADVANTAGE_submenu.push("  PERSONAL PROMOTION");
MARKETINGADVANTAGE_submenu.push("  ADVERTISING");
MARKETINGADVANTAGE_submenu.push("  EXCLUSIVE SERVICES AND PROGRAMS");

var TECHNOLOGY_submenu:Array = new Array();
TECHNOLOGY_submenu.push("  TOOLS TO BUILD YOUR BUSINESS");
TECHNOLOGY_submenu.push("  TOOLS TO MANAGE YOUR BUSINESS");

var SUPPORT_submenu:Array = new Array();
SUPPORT_submenu.push("  IN-HOUSE SERVICES");
SUPPORT_submenu.push("  AFFILIATES AND DIVISIONS");

var activeMenuGroups:Array = new Array();

activeMenuGroups.push(_root.createMenuItemGroupMC("mainmenu", "mainmenu", mainmenuArr, 8, 8));

function createMenuItemGroupMC(type:String, this_name:String, arr:Array, x_loc, y_loc):MovieClip {
	var mc_mg:MovieClip = this.createEmptyMovieClip(this_name, this.getNextHighestDepth());
	mc_mg.mc_type = type;
	mc_mg._x = x_loc;
	mc_mg._y = y_loc;
	mc_mg.active_menu_item = null;
	
	mc_mg.menu_item_width = menu_item_min_width;
	for(var i = 0; i<arr.length; i++) {
		var tmp_width = _root.checkTextLength(arr[i], _root.text_fmt_shadow);
		if(mc_mg.menu_item_width < tmp_width) {
			mc_mg.menu_item_width = tmp_width;
		}
	}
	var y_pointer = 0;
	
	for(var i = 0; i<arr.length; i++) {
		var container_name:String = "";
		var tmp_name:String = arr[i];
		for(var j  = 0; j<tmp_name.length; j++) {
			if(tmp_name.charAt(j) != " ") {
				container_name = container_name + tmp_name.charAt(j);
			}
		}
		var container_mc:MovieClip = mc_mg.createEmptyMovieClip(container_name, mc_mg.getNextHighestDepth());
		container_mc.createMenuItemMC = _root.createMenuItemMC;
		container_mc.text_label = arr[i];
		var mi_mc:MovieClip = container_mc.createMenuItemMC(arr[i], mc_mg.menu_item_width, _root.menu_item_height);
		container_mc.absolute_y = y_pointer+y_loc;
		container_mc._y = y_pointer;
		y_pointer=y_pointer+mi_mc._height;
		mi_mc.menuLoadAnimation = _root.menuLoadAnimation;
		container_mc.addMask = _root.addMask;
		container_mc.addMask(container_mc._width, container_mc._height);
		container_mc._alpha = _root.ALPHA_FLOOR;
		container_mc.onRollOver = _root.raiseAlpha;
		container_mc.onRollOut = _root.lowerAlpha;
		container_mc.onPress = _root.menu_item_select;
		mi_mc.menuLoadAnimation();
	}
	menu_item_bg_id++;
	return mc_mg;
}

function createMenuItemMC(textStr:String, w:Number, h:Number):MovieClip {
	var mc_name = "";
	var this_label = textStr;
	var this_width = w;
	var this_height = h;
	for(var i = 0; i<this_label.length; i++) {
		if(textStr.charAt(i) != " ") {
			mc_name = mc_name+this_label.charAt(i);
		}
	}
	
	var b:MovieClip = new MovieClip();
	b = this.createEmptyMovieClip(mc_name, this.getNextHighestDepth());
	b.createMenuItemBG = _root.createMenuItemBG;
	b.createMenuLabelMC = _root.createMenuLabelMC;
	b.createMenuItemBG(this_width, this_height, _root.menu_dark_grad_color, _root.menu_light_grad_color, _root.menu_border_color);
	b.createMenuLabelMC(this_label, this_width, this_height);
	return b;
}
function createMenuItemBG(w:Number, h:Number, dark_grad:Color, light_grad:Color, border_color:Color):MovieClip {
	//container to hold all the Background MCs.
	var a:MovieClip = new MovieClip();
	a = this.createEmptyMovieClip("menu_item_bg"+_root.menu_item_bg_id, this.getNextHighestDepth());
	
	//create colored gradient movieclip
	a.createEmptyMovieClip("grad",1);
	var colors = [dark_grad,light_grad];
	var alphas = [100,100];
	var ratios = [0x0,0xFF];
	var radians = (Math.PI/2);
	var matrix = { matrixType:"box", x:0, y:0, w:w, h:h, r: radians }
	a.grad.beginGradientFill("linear",colors,alphas,ratios,matrix);
	a.grad.moveTo(0,0);
	a.grad.lineTo(w,0);
	a.grad.lineTo(w,h);
	a.grad.lineTo(0,h);
	a.grad.lineTo(0,0);
	a.grad.endFill();
	
	//create white highlight gradient
	a.createEmptyMovieClip("white_grad",2);
	colors = [0xFFFFFF,0xFFFFFF];
	alphas = [80,0];
	ratios = [0x0,0xFF];
	radians = (Math.PI/2);
	matrix = { matrixType:"box", x:0, y:0, w:w, h:h/2, r: radians }
	a.white_grad.beginGradientFill("linear",colors,alphas,ratios,matrix);
	a.white_grad.moveTo(0,0);
	a.white_grad.lineTo(w,0);
	a.white_grad.lineTo(w,h/2);
	a.white_grad.lineTo(0,h/2);
	a.white_grad.lineTo(0,0);
	a.white_grad.endFill();
	
	//create dark colored border
	a.createEmptyMovieClip("borderMC",3);
	a.borderMC.lineStyle(1, border_color, 100);
	a.borderMC.moveTo(0,0);
	a.borderMC.lineTo(w,0);
	a.borderMC.lineTo(w,h);
	a.borderMC.lineTo(0,h);
	a.borderMC.lineTo(0,0);
	 _root.menu_item_bg_id++;
	return a;
}

function addMask(w:Number, h:Number) {
	var temp_mc:MovieClip = this.createEmptyMovieClip("mask_mc", this.getNextHighestDepth());
	temp_mc.beginFill(0xFFFFFF, 100);
	temp_mc.lineTo(w, 0);
	temp_mc.lineTo(w, h);
	temp_mc.lineTo(0, h);
	temp_mc.lineTo(0,0);
	temp_mc.endFill();
	this.setMask(temp_mc);
}
function menuLoadAnimation() {
      	var easeType = mx.transitions.easing.Regular.easeOut;
        var begin = this._y - 25;
        var end = this._y;
        var time = .5;
        var mc = this;
        _yTween = new mx.transitions.Tween(mc, "_y", easeType, begin, end, time, true);
		_alphaTween = new mx.transitions.Tween( mc, "_alpha", Regular.easeOut, 20, mc._alpha, .5, true );
}
function selectMenuAnimation() {
        var easeType = mx.transitions.easing.Elastic.easeOut;
        var begin = this._x+10;
        var end = this._x;
        var time = .2;
        var mc = this;
        _yTween = new mx.transitions.Tween(mc, "_x", easeType, begin, end, time, true);
}
function unselectMenuAnimation() {
        easeType = mx.transitions.easing.Elastic.easeOut;
        var begin = this._x-10;
        var end = this._x;
        var time = .2;
        var mc = this;
        _yTween = new mx.transitions.Tween(mc, "_x", easeType, begin, end, time, true);

}
function raiseAlpha() {
	this._alpha = _root.ALPHA_CEILING;
}
function lowerAlpha() {
	if(this._parent.active_menu_item != this) {
		this._alpha = _root.ALPHA_FLOOR;
	}
}
function menu_item_select() {
	var temp_mc:MovieClip = this._parent.active_menu_item;
	if(temp_mc == this) {
		this._parent.active_menu_item = "";
		this.unselectMenuAnimation = _root.unselectMenuAnimation;
		this.unselectMenuAnimation();
		var mcs_removed:Array = new Array();
		for(var i = 0; i<_root.activeMenuGroups.length; i++) {
			if(_root.activeMenuGroups[i]._name == this._name) {
				mcs_removed=_root.activeMenuGroups.splice(i, _root.activeMenuGroups.length-i);
			}
		}
		for(var i = 0; i<mcs_removed.length; i++) {
			mcs_removed[i].unloadMovie();
		}
	} else {
		temp_mc._alpha = _root.ALPHA_FLOOR;
		this.selectMenuAnimation = _root.selectMenuAnimation;
		var mcs_removed:Array = new Array();
		for(var i = 0; i<_root.activeMenuGroups.length; i++) {
			if(_root.activeMenuGroups[i]._name == temp_mc._name) {
				mcs_removed=_root.activeMenuGroups.splice(i, _root.activeMenuGroups.length-i);
			}
		}
		for(var i = 0; i<mcs_removed.length; i++) {
			mcs_removed[i].unloadMovie();
		}
		this.selectMenuAnimation();
		this._parent.active_menu_item = this;
		var next_X = this._parent._x+this._width;
		if(_root.getSubmenu(this._name)!=null) {
			_root.activeMenuGroups.push(_root.createMenuItemGroupMC("submenu", this._name, _root.getSubmenu(this._name), next_X, this.absolute_y));
		} else {
			_root.content_window_mc.txt_object.changeTitle(this.text_label);
		}
	}
	mcs_removed = null;
}

function getSubmenu(str:String):Array {
	tmpArr = eval("_root."+str+"_submenu");
	if(tmpArr.length > 0) {
		return tmpArr;
	} else {
		return null;
	}
}
Here is my menu item label code which creates the label/title that is on each menu item:
Code:
var font_size = 12;
var font_name = "verdana";
var is_bold = true;
var shadow_color = 0x330000; //really dark red
var light_color = 0xFFFFFF;
var text_indent = 0;

var text_fmt_shadow:TextFormat = new TextFormat()
text_fmt_shadow.color = shadow_color;
text_fmt_shadow.bold = is_bold;
text_fmt_shadow.size = font_size;
text_fmt_shadow.font = font_name;
text_fmt_shadow.indent = text_indent;

var text_fmt_light:TextFormat = new TextFormat()
text_fmt_light.color = light_color;
text_fmt_light.bold = is_bold;
text_fmt_light.size = font_size;
text_fmt_light.font = font_name;
text_fmt_light.indent = text_indent;

//a = _root.createMenuLabelMC("TOOLS TO BUILD YOUR BUSINESS");
//a.onRollOver = _root.changeLightTextColor;
//a.onRollOut = _root.changeLightTextColor;

function changeLightTextColor() {
	if(this.text_light.textColor == 0xFF0000) {
		this.text_light.textColor = 0xFFFFFF;
	} else {
		this.text_light.textColor = 0xFF0000;
	}
}

function createMenuLabelMC(str:String, w, h):MovieClip {
	this.createEmptyMovieClip("menu_label", this.getNextHighestDepth());
	
	this.menu_label.createTextField("text_dark", this.menu_label.getNextHighestDepth(), 1, 1, w, h);
	this.menu_label.text_dark.autoSize="left";
	this.menu_label.text_dark.type="dynamic";
	this.menu_label.text_dark.selectable="false";
	this.menu_label.text_dark.text=str;
	this.menu_label.text_dark.setTextFormat(_root.text_fmt_shadow);
	
	this.menu_label.createTextField("text_light", this.menu_label.getNextHighestDepth(), 0, 0, w, h);
	this.menu_label.text_light.autoSize=		"left";
	this.menu_label.text_light.type=			"dynamic";
	this.menu_label.text_light.selectable=		"false";
	this.menu_label.text_light.text=			str;
	this.menu_label.text_light.setTextFormat(_root.text_fmt_light);
	return this.menu_label;
}

function checkTextLength(str:String, fmt:TextFormat):Number {
	_root.createEmptyMovieClip("test_text_mc", _root.getNextHighestDepth());
	test_text_mc.createTextField("test_text", _root.getNextHighestDepth(), 0, 0, 100, 100);
	test_text_mc.test_text.text=str;
	test_text_mc.test_text.setTextFormat(fmt);
	test_text_mc.test_text.autoSize="left";
	var tmp_text_width = test_text_mc.test_text._width+10;
	test_text_mc.unloadMovie();
	return tmp_text_width;
}

Thanks
 
....Anyways, I decided not to use the scrollPane component and so I just created my own pageUp and pageDown tweens. I'm not using a scroll bar, but just two arrow movieclips that use onRollOver and onRollOut to move the movieclip up and down. I also had to use setInterval() and clearInterval to keep the movieclip moving up and down since onRollOver is a one-time event. It worked out well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top