PDA

View Full Version : Talking to a movieclip.... inside a movie clip


Stevenjs86
08-02-2008, 06:55 PM
OK,

What i am trying to accomplish:
- i have a series of labeled frames in a movie clip (9 total)
- the frames are simply labeled by there frame number (currently)
- in each one of those frames is another movie clip (just one)
- each movie clip is labeled the same (they are different movie clips, but i have tagged them the same, and they are each on a different time frame)
- in each of those movie clips in each of those frames have a series of labeled frames (6 total)
- (labeled A,B,C,D,U,F)
- when i press a button (depending on which button i press) I would like flash to navigate to a specific frame in movie clip one, and then to a specific frame in the movie clip in side that movie clip.

The code i have written will do it as long as i am only movie one frame at a time before it stops reading the script (i.e. i can move to frame 4 or i can move to frame C, just not frame 4 then frame c in movieClip1_mc in frame 4


var movieClips1:Array;
var movieClips2:Array;

var movieClip1:Number = 0;
var movieClip2:Number = 0;
var movieClipPlaceHolder:Number = 0;

var keyPressed:uint;
var F1KeyIsDown:Boolean
var F2KeyIsDown:Boolean
var F3KeyIsDown:Boolean

var movieClipChange:Boolean


function initializeGame():void
{
F1KeyIsDown = false;
F2KeyIsDown = false;
F3KeyIsDown = false;

movieClipChange = false;

movieClips1 = [1,2,3,4,5,6,7,8,9];
movieClips2 = ["A","B","C","D","U","F"];

/*Note I have set an array instead of using straight frame #s so that i can (in the future
Write a code that allows me to find out how many frames are total, and then give me those numbers
as the array*/


stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
stage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);
}

function pressKey(event:KeyboardEvent):void
{
keyPressed = event.keyCode;
changeMovieClip();
}

function releaseKey(event:KeyboardEvent):void
{
var thisKey:uint = event.keyCode;
if(thisKey == Keyboard.F1)
{
F1KeyIsDown = false;
}
if(thisKey == Keyboard.F2)
{
F2KeyIsDown = false;
}
if(thisKey == Keyboard.F3)
{
F3KeyIsDown = false;
}
}

function changeMovieClip():void
{
if(keyPressed == Keyboard.F1 && F1KeyIsDown == false && movieClip2 < 4)
{
if(movieClip1 == 3)
{
movieClipPlaceHolder = 0;
}
if(movieClip1 < 3)
{
movieClipPlaceHolder += 1;
}

movieClip2 = movieClipPlaceHolder;
F1KeyIsDown = true;
}
if(keyPressed == Keyboard.F2 && F2KeyIsDown == false && movieClip2 < 4)
{
if(movieClip2 > 0 && movieClip2 < 4)
{
movieClipPlaceHolder -= 1;
}
if(movieClip2 == 0)
{
movieClipPlaceHolder = 3;
}

movieClip2 = movieClipPlaceHolder;
F2KeyIsDown = true;
}
if(keyPressed == Keyboard.F3 && F3KeyIsDown == false && movieClip1 <= 8)
{
movieClip1 += 1
F3KeyIsDown = true;
}
movieClip1_mc.gotoAndStop(movieClips1[movieClip1]);
movieClip1_mc.movieClip2_mc.gotoAndStop(movieClips 2[movieClip2]);

/*notice when you change the value of movieClip1 it will change the frame on movieClip1_mc,
but it will not read the next line and change the value of movieClip2_mc*/



}

initializeGame();


------ END SCTRIPT------

I know this might be a confusing set of code, but its going to be part of a much bigger picture.
So any other bugs you find in it would be appreciated,
but most importantly the talking to 2 movie clips.

Stevenjs86
08-03-2008, 10:21 AM
So i was thinking about the problem and i thought a possible solution is a string of code that tells the stage to refresh. This way it would reconize where the movie clips are and what state they are supposed to be in. then i could call to the second movie clip.

let me know if you can come up with anything that would fit this.

Stevenjs86
08-04-2008, 05:02 PM
Or if there is a way to simulate the code stopping, and then starting again so its as if everything finished, then i took the next step. Because once the code stops running and i try to talk to the MC inside the MC it works fine.

Thanks
Steven