0
votes

So, I'm very much a beginner in AS3. I've been reading and figuring out things as I go, though I can't wrap my head around this.

So, I have 4 frames. Each frame has a different movie clip, MC1,MC2,MC3,MC4 Inside those four movie clips, there is another movie clip with the same instance name for each: BC, and inside that movie clip there are two frames. Frame 1 has a dot, and frame 2 does not. MC1>BC>(2 frames) MC2>BC>(2 frames) and so on....

What I'm trying to do: I wanted to see if there was any way to control the frame navigation of BC inside all four MC clips at the same time with one button. I want to switch back and fourth between the two frames inside the BC movie clip. I'm at a loss, I've tried quite a few things.

1
You cannot access anything that has no instance at the current frame. You cannot address a MovieClip at the another frame because it does not exist. Then, you can make a variable var BCframe:int = 2; then in the first frame of BC address it: gotoAndStop((parent.parent as MovieClip).BCframe); So, when any BC comes to be, it addresses your main timeline and figures the correct frame to go to.Organis

1 Answers

0
votes

You should be able to do so by giving them all the same instance name (so long as there is only ever one of them on screen at once).

So lets say you have a button that spans all 4 frames with an instance name of navBtn and you gave each of the MC1-4 clips the same instance name of MC. You could do the following on frame 1:

navBtn.addEventListener(MouseEvent.CLICK, navBtnClick);

function  navBtnClick(e:Event):void {
    if(MC.BC.currentFrame == 2){
        MC.BC.gotoAndStop(1);
    }else{
        MC.BC.gotoAndStop(2);
    }
}

Reading your question again, perhaps what are looking for is to have each clip automatically go to the same frame for their BC child when they load? If that is the case, then follow the example in the comment on your question by @Organis. Here is one way you could accomplish this:

Create two variable on frame one of your main timeline:

var BC_NAV_CHANGE:String = "BC_NAV_CHANGE";
var BC_CurFrame:int = 1;

Then, when you need to change the frame of the BC objects, do the following:

//create a function that you call when you want to change the BC frame
function toggleBCFrame(e:Event = null){
    MovieClip(root).BC_CurFrame = MovieClip(root).BC_CurFrame == 1 ? 2 : 1;
    //the line above is a if/else shorthand, that is setting a new value to the `BC_CurFrame` var, 
    //if the current value is `1`, it will set it to `2`, otherwise it will set it to `1`

    MovieClip(root).dispatchEvent(new Event(MovieClip(root).BC_NAV_CHANGE));
    //this line (above) dispatches a event telling anything that's listening that the variable has changed
}

If the code above is on the main timeline, you can forgo all the MovieClip(root). parts of the code.

Now, on the timeline of your BC MovieClip(s), put the following code:

//create a function that goes to and stops at the frame stored in the global variable
function updateFrame(e:Event = null){
    gotoAndStop(MovieClip(root).BC_CurFrame);
}

//next listen for the BC_NAV_CHANGE event, and call the above update function above any time that event happens
MovieClip(root).addEventListener(MovieClip(root).BC_NAV_CHANGE, updateFrame);

//lastly, call the update function right away so when the BC clips loads it immediately goes to the correct frame
updateFrame();