Loading one of 3 movies into an mc

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.

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)?

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

_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:

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.

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?

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’…

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… :smiley:

_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 :wink:

Ohh this is doin my head in :stuck_out_tongue:

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.

oke tested it agaie :stuck_out_tongue:
It all works here!

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);

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


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");
	}
}

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]:stuck_out_tongue:

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

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

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.:!:

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 :smiley:

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

Thanks much, appreciated :slight_smile:

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?