# \[FMX\]Substract part of instance name in function

**URL:** <https://forum.kirupa.com/t/fmx-substract-part-of-instance-name-in-function/117963>\
**Category:** Uncategorized\
**Created:** [August 1, 2004, 1:41pm UTC](https://forum.kirupa.com/t/fmx-substract-part-of-instance-name-in-function/117963 "2004-08-01T13:41:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)\
**Post date:** [August 1, 2004, 1:41pm UTC](https://forum.kirupa.com/t/fmx-substract-part-of-instance-name-in-function/117963/1 "2004-08-01T13:41:44Z")

</div>

Hi everybody,

I have the following code from a tutorial on Kirupa:

```auto
_root.currMovie = "home";
container.loadMovie(_root.currMovie+".swf");
_root.home.gotoAndStop(2)
newThis=home
MovieClip.prototype.Pressed = function() {
this.onPress = function() {
if (_root.currMovie == undefined) {
_root.currMovie = this._name;
_root.container.loadMovie(this._name+".swf");
} else if (_root.currMovie != this._name) {
if (_root.container._currentframe>=_root.container.midframe) {
	_root.currMovie = this._name;
	_root.container.play();
}
}
newThis = this;
_global.oldThis.play();
this.gotoAndStop(2);
};
};
_root.home.Pressed();
_root.about.Pressed();
_root.service.Pressed();
_root.contact.Pressed();

```

It is used to make transitions between different swf’s. My question i about the laodMovie part.

[color=red]\_root.container.loadMovie(this.\_name+".swf");[/color]

As you can see are the button names: home, about, service and contact. This are also the names of the external swf’s. But now I have chanced my button names in: [color=red]btn\_home, btn\_about, etc[/color]. Now is it a little stange to name my external swf’s btn\_home etc, so how can I substract the prefix [color=red]btn\_[/color] from the buttons so that the externa swf’s can keep their normal names? I know it has something to do with substr but I don’t know how and where to implement it.

Anybody with an answer?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Dodger](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@Dodger](https://forum.kirupa.com/u/Dodger)\
**Post date:** [August 2, 2004, 5:33am UTC](https://forum.kirupa.com/t/fmx-substract-part-of-instance-name-in-function/117963/2 "2004-08-02T05:33:42Z")

</div>

Why you added the prefix to the buttons :puzzle:

---

<div class="post-metadata">

**Author:** ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)\
**Post date:** [August 2, 2004, 5:41am UTC](https://forum.kirupa.com/t/fmx-substract-part-of-instance-name-in-function/117963/3 "2004-08-02T05:41:19Z")

</div>

To control the over, out and release state of the buttons with a [color=blue]for in[/color] loop 🙂

---

<div class="post-metadata">

**Author:** ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)\
**Post date:** [August 2, 2004, 7:19am UTC](https://forum.kirupa.com/t/fmx-substract-part-of-instance-name-in-function/117963/4 "2004-08-02T07:19:40Z")

</div>

Maybe that the next explenation is a bit clearer. I have 6 buttons on the main stage: (btn\_home, btn\_about, …btn\_contact) and I have an equal amount of external movies to load in a container on the stage (name container) I have the following function to control the buttons and to load the external movies:

```auto
for (var i in this) {
 if (this*._name.substr(0, 4) == "btn_") {
  setButton(this*._name);
 }
}
function setButton(clip) {
 var clip = eval(clip);
 clip.onRelease = function() {
  if (_root.currMovie == undefined) {
   [color=red]_root.currMovie = this._name;[/color]
[color=blue]// I tried _root.currMovie = this._name.substr(4);[/color][color=#ff0000]
[/color] this._parent.container.loadMovie(this._name+".swf");
  } else if (_root.currMovie != this._name) {
   if (this._parent.container._currentframe>=this._parent.container.midframe) {
	_root.currMovie = this._name;
[color=#0000ff]// I tried _root.currMovie = this._name.substr(4);[/color]
	this._parent.container.play();
   }
  }
 };
}

```

When I press one of the buttons, i get the following error:

[color=red]Error opening URL “[/color][[color=red]file:btn\_homede.swf[/color]](file:///D|/Lamai%20Motor%20Land/btn\_homede.swf)[color=red]”[/color]  
[color=#ff0000][/color]  
[color=black]I tried to add a substr(4) to parts marked red in the function, but without result. What am I doing wrong?[/color]

Thanks in advance
