# Loading one of 3 movies into an mc

**URL:** <https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139>\
**Category:** Uncategorized\
**Created:** [March 24, 2006, 3:58am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139 "2006-03-24T03:58:33Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 24, 2006, 3:58am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/1 "2006-03-24T03:58:33Z")

</div>

Hi all

I have a cocktail application - whatever alphabet key is hit (k, for example), one of 3 cocktail recipie swf’s (k1.swf, k2.swf, k3.swf) is loaded into the content MC.

It may always load the same one initially, or randomly one of the three - either way, it cycles through those 3 if you hit that key repeatedly.

Same goes for any other keys.

I’ve got the listeners etc in place, and the code set out, I just don’t know what exactly to chuck in, so that it for example calls from an array a1.swf, a2.swf, a3.swf from the same directory, when hit.

Would be lovely to be kicked in the right direction.

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 6:15am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/2 "2006-03-25T06:15:10Z")

</div>

ie, how can I get this

if (Key.getAscii() == 65, 97) {  
loaded\_mc.loadMovie(‘a1.swf’)  
}

…to instead load a2.swf if a1.swf is already loaded, then a3.swf if a2.swf is already loaded when a is pressed again (ie, cycling through those 3 only if repeatedly pressed)?

---

<div class="post-metadata">

**Author:** ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)\
**Post date:** [March 25, 2006, 7:38am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/3 "2006-03-25T07:38:48Z")

</div>

Did not undrestand you campletely, but maybe something like this? 🙂

```auto
_root.theAKey = 0;

///////////////////////////////

if (Key.getAscii() == 65, 97) {
   if(_root.theAKey = 3){
      _root.tehAKey = 0;
   }
   _root.theAKey++;
   loaded_mc.loadMovie("a" + root.theAKey + ".swf");
}

```

first of all the var root.theAKey is set to 0.  
Then if a key is hit, he checks if root.theAKey is 3, if so he makes it 0 again.  
Next this he does, is adding 1 to root.theAKey using the ++  
And then finally it loads the swf like this:

If root.theAKey = 1, then it will load a1.swf… and so on…  
Till root.theAKey will become 3, then its reset to 0 so it you will load a1.swf again.

:rambo:

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 8:13am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/4 "2006-03-25T08:13:27Z")

</div>

Thats excellent, thanks mate - it makes perfect sense, however I couldn’t get it going on my end.

Or maybe my comp has decided to be a prick for not being allowed any downtime lately…

Here’s my code, with B as well, just as a test.

```auto
stop();

_root.theAKey = 0;
_root.theBkey = 0;

watchKeyboard = new Object();
watchKeyboard.onKeyUp = function() {

	if (Key.getAscii() == 65, 97) {
   if(_root.theAKey = 3){
      _root.theAKey = 0;
   }
   _root.theAKey++;
   loaded_mc.loadMovie("a" + _root.theAKey + ".swf");
}

if (Key.getAscii() == 66, 98) {
   if(_root.theBKey = 3){
      _root.theBKey = 0;
   }
   _root.theBKey++;
   loaded_mc.loadMovie("a" + _root.theBKey + ".swf");
}
		
}

Key.addListener(watchKeyboard);

```

Basically there is a “timeline” MC on the root timeline, and within this, is the loaded\_mc clip.

Currently, no matter what key I hit, ‘a1.swf’ is being loaded in. I’m pretty sure the ascii codes are correct (capital and uppercase for eacH).

Any ideas?

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 8:45am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/5 "2006-03-25T08:45:14Z")

</div>

loaded\_mc.loadMovie(“a” + \_root.theBKey + “.swf”);

One error in the above was fixed (oopel daidy), so b1 (only) now loads - but it wont go to ‘a’ if i hit ‘a’…

---

<div class="post-metadata">

**Author:** ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)\
**Post date:** [March 25, 2006, 9:08am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/6 "2006-03-25T09:08:00Z")

</div>

```auto
stop();

_root.theAKey = 0;
_root.theBKey = 0;

watchKeyboard = new Object();
watchKeyboard.onKeyUp = function() {

    if (Key.getAscii() == 97 || 65) {
        if(_root.theAKey == 3){
            _root.theAKey = 0;
        }
        _root.theAKey++;
        loaded_mc.loadMovie("a" + _root.theAKey + ".swf");
    }

    if (Key.getAscii() == 98 || 66) {
        if(_root.theBKey == 3){
            _root.theBKey = 0;
        }
        _root.theBKey++;
        loaded_mc.loadMovie("b" + _root.theBKey + ".swf");
    }
    
}

Key.addListener(watchKeyboard);

```

Lol, just a few mistake by me and you… 😃

---

<div class="post-metadata">

**Author:** ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)\
**Post date:** [March 25, 2006, 9:10am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/7 "2006-03-25T09:10:54Z")

</div>

> \_root.theAKey = 0;[FONT=monospace]  
> [/FONT]\_root.theB\*\*[COLOR=Red]k[/COLOR]\*\*ey = 0;

> if (\_root.theAKey =[COLOR=Red] **=** [/COLOR] 3){

> if (Key.getAscii() == 97 **[COLOR=Red]||[/COLOR]** 65)

:lol:

Now should work perfectly 😉

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 9:18am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/8 "2006-03-25T09:18:27Z")

</div>

Ohh this is doin my head in 😛

Thanks Bokke, but now it’s only cycling through ‘B’, for any key :S. I jsut can’t see any errors this time around…

When I add other keys, it only works with the last letter in the chain, ie, only C works now that it’s in.

---

<div class="post-metadata">

**Author:** ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)\
**Post date:** [March 25, 2006, 9:22am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/9 "2006-03-25T09:22:20Z")

</div>

oke tested it agaie 😛  
It all works here!

```auto
stop();

_root.theAKey = 0;
_root.theBKey = 0;

watchKeyboard = new Object();
watchKeyboard.onKeyUp = function() {

    if (Key.getAscii() == 97 || Key.getAscii() == 65) {
        if(_root.theAKey == 3){
            _root.theAKey = 0;
        }
        _root.theAKey++;
        trace("a" + _root.theAKey + ".swf");
    }
    if (Key.getAscii() == 98 || Key.getAscii() == 66) {
        if(_root.theBKey == 3){
            _root.theBKey = 0;
        }
        _root.theBKey++;
        trace("b" + _root.theBKey + ".swf");
    }
}

Key.addListener(watchKeyboard);

```

---

<div class="post-metadata">

**Author:** ![999](https://avatars.discourse-cdn.com/v4/letter/9/c5a1d2/32.png) [@999](https://forum.kirupa.com/u/999)\
**Post date:** [March 25, 2006, 9:26am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/10 "2006-03-25T09:26:19Z")

</div>

Im really bad with Key listeners but this might do what you want it too.

```auto

loadMC = function(m1, m2, m3) {
	if(m1 != mcArray[0]){
		mc = undefined;
		}mcArray = [m1, m2, m3];
	if (mc == undefined) {
		mc = mcArray[Math.floor(Math.random()*3)];
		} else if (mc == mcArray[0]) {
		mc = mcArray[1];
		 } else if (mc == mcArray[1]) {
		mc = mcArray[2];
		 } else if (mc == mcArray[2]) {
			 mc = mcArray[0];
		 }loaded_mc.loadMovie(mc);
}

Key.addListener(_root);
_root.onKeyDown = function() {
	if (Key.getAscii() == 97) {
		loadMC("a1.swf", "a2.swf", "a3.swf");
		}if (Key.getAscii() == 98) {
		loadMC("b1.swf", "b2.swf", "b3.swf");
		}if (Key.getAscii() == 99) {
		loadMC("c1.swf", "c2.swf", "c3.swf");
	}
}

```

---

<div class="post-metadata">

**Author:** ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)\
**Post date:** [March 25, 2006, 9:28am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/11 "2006-03-25T09:28:29Z")

</div>

It was the [COLOR=Red]“Key.getAscii() == 97 || Key.getAscii() == 65”[/COLOR]

\*\* edit:\*\*

Oh and you maybe want to replace the [COLOR=Red]“trace”[/COLOR] with [COLOR=Red]“loaded\_mc.loadMovie”[/COLOR]  
[COLOR=DarkSlateGray][COLOR=Red]  
[/COLOR][/COLOR]😛

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 9:47am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/12 "2006-03-25T09:47:01Z")

</div>

Ohhh yeah, I killed the trace thing 🙂 But with that last syntax addition, its working perfect now, cheers BOKKE 😃

@999 - I really like this method too. But I got a ‘infinite loop’ (or words to that effect), error…

---

<div class="post-metadata">

**Author:** ![999](https://avatars.discourse-cdn.com/v4/letter/9/c5a1d2/32.png) [@999](https://forum.kirupa.com/u/999)\
**Post date:** [March 25, 2006, 10:02am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/13 "2006-03-25T10:02:02Z")

</div>

Strange? It works fine here. Not that you need it now but heres an example zip thats seems to load fine.

//Edit

Besides the fact that there are two b3 clips in the zip.:!:

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 10:16am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/14 "2006-03-25T10:16:31Z")

</div>

haha, all good. I couldnt check out the fla though - using mx2004 here, which may possibly have something to do with it?

edit - bugger me, it now works (? - !) - thanks much guys 😃

---

<div class="post-metadata">

**Author:** ![999](https://avatars.discourse-cdn.com/v4/letter/9/c5a1d2/32.png) [@999](https://forum.kirupa.com/u/999)\
**Post date:** [March 25, 2006, 10:27am UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/15 "2006-03-25T10:27:53Z")

</div>

Forgot what forum I was in. Heres a 2004 version anyway.

---

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [March 25, 2006, 1:23pm UTC](https://forum.kirupa.com/t/loading-one-of-3-movies-into-an-mc/183139/16 "2006-03-25T13:23:28Z")

</div>

Thanks much, appreciated 🙂

One last thing, if anyone is willing. I have an intro and outro for all of the loaded clips - the intro is easy, but i’d like the outro of the currently loaded clip to be played before the next one is when the key is pressed (and also stop any keys from being activated during this transition).

Just so aesthetically, it wll works smoothly.

I imagine something will be needed in the LoadMC function?
