# \[FMX\] how to give button multiple commands

**URL:** <https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160>\
**Category:** flash\
**Created:** [January 27, 2003, 7:25pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160 "2003-01-27T19:25:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcs](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@jcs](https://forum.kirupa.com/u/jcs)\
**Post date:** [January 27, 2003, 7:25pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/1 "2003-01-27T19:25:03Z")

</div>

I have this code on a button that relates to AS elsewhere in the movie (this works fine, BTW):

on (release) {  
targety = -534;  
targety2 = -813;  
targety3 = 110;  
targetx1 = -100;  
}

and I want to add the following to the same on (release) command:

```
_root.createEmptyMovieClip("container", 1);
loadMovie("style.swf", "container");
container._x = 100;
container._y = 25 ;

```

But I don’t know the proper syntax to make both work. Please advise. (Note: style.swf is in same local folder as the main movie)

Thanks,  
JC

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 7:30pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/2 "2003-01-27T19:30:20Z")

</div>

on (release) {  
targety = -534;  
targety2 = -813;  
targety3 = 110;  
targetx1 = -100;  
\_root.createEmptyMovieClip(“container”, 1);  
container.\_x = 100;  
container.\_y = 25 ;  
loadMovie(“style.swf”, “container”);  
}

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 7:42pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/3 "2003-01-27T19:42:01Z")

</div>

Thanks G!  
While I have you, two more quesitons:

1. how would I use something like setInterval to load that movie a second after on(release)

2. I have four buttons like this. How best to unloadMovie when a different button is pressed?

eg. a button called “style” loads one movie, a button called “travel” loads a different movie into the same location. If “style” has loaded and I want to go to “travel,” would I put unloadMovie as the first line on the “travel” button? Or no?=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 7:47pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/4 "2003-01-27T19:47:49Z")

</div>

re:#1 - its very complicated, and i´m in a hurry (off to home now). do a search here @ kirupa on **setinterval** , senocular already had made this here…

re:#2 - just load all movies on the same level, and when you load another one the older will be raplaced 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 7:51pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/5 "2003-01-27T19:51:26Z")

</div>

thanks, will do.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 8:03pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/6 "2003-01-27T20:03:25Z")

</div>

> \*Originally posted by Guig0 \*  
> \*\*re:#1 - its very complicated, and i´m in a hurry (off to home now). do a search here @ kirupa on **setinterval** , senocular already had made this here… \*\*

Woah…complicated? Well basicaly The setInterval function is used to create an event that repeats continuously until the Flash movie is closed or the clearInterval function is passed.

Anywho, i didn’t see senocular’s post, but here you go:

Simply, just insert your loading process into a function, and then on load, (which i’ll be working on it now) clear that interval! after the function, set an interval to that function for something like, 5000 millisecond. I’ll try making a code for that one now!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 8:21pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/7 "2003-01-27T20:21:27Z")

</div>

so something like…

on (release) {  
targety = -534;  
targety2 = -813;  
targety3 = 110;  
targetx1 = -100;  
\_root.createEmptyMovieClip(“container”, 1);  
container.\_x = 100;  
container.\_y = 25 ;

function pause(){  
\_root.loadMovie(“style.swf”, “container”);  
clearInterval(delay);  
}  
delay = setInterval(pause, 6000);  
stop();

:q: (-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 8:23pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/8 "2003-01-27T20:23:15Z")

</div>

Done!

```php
myLoadVars = new LoadVars();
myLoadVars._parent = this;
myFunction = function () {
	myLoadVars.onLoad = function(success) {
		if (success) {
			var nm = this._parent.createEmptyMovieClip("swfHolder", 1);
			nm.loadMovie("myfile.swf");
			clearInterval(myInterval);
		} else {
			trace("error loading your movie");
		}
	};
	myLoadVars.load("myfile.swf");
};
myInterval = setInterval(myFunction, 2500);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 8:26pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/9 "2003-01-27T20:26:59Z")

</div>

> \*Originally posted by jcs \*  
> **function pause(){  
> \_root.loadMovie(“style.swf”, “container”);  
> clearInterval(delay);  
> }  
> delay = setInterval(pause, 6000);**

ehh emm, no! Your clearing the interval this way, and therefore, your file will never get loaded, the example in my above post shows the working way, as i said, when your file get _loaded_, then the interval will be cleared!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 8:55pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/10 "2003-01-27T20:55:59Z")

</div>

HA! It’s gota be amusing for those of you in the know watching newbies like myself stumble through some tidbits of code! :beam:

works like a charm, except:

a couple seconds after the function is called and the movie loaded, the movie on main movie reloads behind the emptyMovieClip. Only does it once, that I can tell.  
Thoughts?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 9:29pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/11 "2003-01-27T21:29:07Z")

</div>

> \*Originally posted by jcs \*  
> \*\*a couple seconds after the function is called and the movie loaded, the movie on main movie reloads behind the emptyMovieClip. Only does it once, that I can tell.  
> Thoughts? \*\*

Did you add a stop action in the last frame of your main movie?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 10:10pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/12 "2003-01-27T22:10:40Z")

</div>

i have, but it was still happening. However I closed and reopened and the problem has taken care of itself.

will let you know, though.

Thanks a lot, h88. 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 10:17pm UTC](https://forum.kirupa.com/t/fmx-how-to-give-button-multiple-commands/12160/13 "2003-01-27T22:17:45Z")

</div>

No problem, am glad you got it working!
