# \[AS2\] attachMovie ObjName outside of function

**URL:** <https://forum.kirupa.com/t/as2-attachmovie-objname-outside-of-function/265576>\
**Category:** flash\
**Created:** [July 10, 2008, 12:12pm UTC](https://forum.kirupa.com/t/as2-attachmovie-objname-outside-of-function/265576 "2008-07-10T12:12:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattpodge](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@mattpodge](https://forum.kirupa.com/u/mattpodge)\
**Post date:** [July 10, 2008, 12:12pm UTC](https://forum.kirupa.com/t/as2-attachmovie-objname-outside-of-function/265576/1 "2008-07-10T12:12:37Z")

</div>

Hello all

I am currently developing an interactive location map of the UK for a client. Every region of the map is a button that, when click, zooms in towards the viewer whilst all the others fade in the background.

This i can do fine with a single function. However the movieClip that is loaded with attachMovie contains buttons that I simply cannot target for any other function. I believe it is something to do with the attachMovie ObjName not being accessible outside of the function they’re created in. I have been trying \_global variables but still I cannot assign actions to the buttons.

Please, if some one could just take a look at my code and point me in the right direction so that when I click any of the buttons in the attachMovie I at least get a trace function to work.

I have attached my complete actionscript but the section I’m struggling with is displayed below.

```auto

//zoom in
function focus (target_mc:MovieClip, scale_mc:Number, sec:Number, target_x:Number, target_y:Number, focus_mc:String) {
	
	_global.focus_Name = "_focus";
	_global.back_Button = focus_mc + "_back";

	if (ireland._alpha == 100) {

		var zoomInTween:Tween = new Tween(target_mc, "_xscale", Regular.easeOut, target_mc._xscale, scale_mc, sec, true);
											new Tween(target_mc, "_yscale", Regular.easeOut, target_mc._yscale, scale_mc, sec, true);
											new Tween(target_mc, "_x", Regular.easeOut, target_mc._x, 185, sec, true);
											new Tween(target_mc, "_y", Regular.easeOut, target_mc._y, 177.5, sec, true);

		fadeoutAll(target_mc);
		disableAll(target_mc);

		zoomInTween.onMotionFinished = function() {
			_root.attachMovie(focus_mc ,focus_Name, 100, {_x:185, _y:177.5, _xscale:scale_mc, _yscale:scale_mc});
			_root.attachMovie("back_btn" ,back_Button, 200, {_x:10, _y:10, _xscale:14.3, _yscale:14.3});
		}

	} else {

		removeMovieClip("_focus");
		removeMovieClip(back_Button);

		var zoomOutTween:Tween = new Tween(target_mc, "_xscale", Regular.easeOut, target_mc._xscale, 50, sec, true);
												new Tween(target_mc, "_yscale", Regular.easeOut, target_mc._yscale, 50, sec, true);
												new Tween(target_mc, "_x", Regular.easeOut, target_mc._x, target_x, sec, true);
												new Tween(target_mc, "_y", Regular.easeOut, target_mc._y, target_y, sec, true);
												
		fadeinAll(target_mc);
		enableAll();
	}
}

//beds, bucks, herts & northants
beds.onRollOver = function() {
	colourswapper(beds,"0xFFADEA");
};

beds.onRollOut = function() {
	colourswapper(beds,"0xCE8BBC");
};

beds.onRelease = function() {
	focus(beds, 400, 0.5, 267.9, 282.8, "beds_focus");
	trace (back_Button);
	trace (focus_Name);
};

beds.beds_focus_back.onRelease = function () {
	trace ("It works!");
}

```

---

<div class="post-metadata">

**Author:** ![mattpodge](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@mattpodge](https://forum.kirupa.com/u/mattpodge)\
**Post date:** [July 10, 2008, 3:50pm UTC](https://forum.kirupa.com/t/as2-attachmovie-objname-outside-of-function/265576/2 "2008-07-10T15:50:37Z")

</div>

has been solved, thank you

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [July 10, 2008, 3:57pm UTC](https://forum.kirupa.com/t/as2-attachmovie-objname-outside-of-function/265576/3 "2008-07-10T15:57:13Z")

</div>

Well done…feel free to leave a clue to the solution for future reference 😉
