Skip to main content
Participating Frequently
March 4, 2012
解決済み

Goto frame of child movieclip on later frame

  • March 4, 2012
  • 返信数 4.
  • 1088 ビュー

Hi, I've been trying to find a tutorial or description on how to do this.  Sorry if I'm asking something repetitive but I can't seem to find the right way to search for it or find something that explains it.

What I'm trying to do is click btn1 on mc1 timeline frame 1 that will goto and play mc1 timeline frame 30 where the child mc2 is, then play mc2 at frame 10.

I know this won't work as mc2 doesn't exist til frame 30 but to give an idea

btn1.addEventListener(MouseEvent.MOUSE_UP, release1);

function release1(evt:MouseEvent):void {

this.gotoAndPlay(30).mc2(10);

}

kind of like how you can go to a frame label in a scene

mc1.gotoAndPlay("intro", "Scene 12");

From what I've gathered so far it's using integers?

Thanks for any help.

このトピックへの返信は締め切られました。
解決に役立った回答 kglad

use:

btn1.addEventListener(MouseEvent.MOUSE_UP, release1);

function release1(evt:MouseEvent):void {

this.addEventListener(Event.RENDER,renderF);

stage.invalidate();

this.gotoAndPlay(30);

}

function renderF(e:Event):void{

this.removeEventListener(Event.RENDER,renderF);

mc2.gotoAndPlay(10);

}

返信数 4

macneil2222作成者
Participating Frequently
March 4, 2012

Thanks again... I've learnt from both of you, although I did go with the RENDER as it kept the code in one place and it was the first reply lol

I used this and it works fine:

btn1.addEventListener(MouseEvent.MOUSE_UP, release1);

btn2.addEventListener(MouseEvent.MOUSE_UP, release2);

btn3.addEventListener(MouseEvent.MOUSE_UP, release3);

function release1(evt:MouseEvent):void {

this.addEventListener(Event.RENDER,renderF);

stage.invalidate();

this.gotoAndStop(30);

}

function renderF(e:Event):void{

this.removeEventListener(Event.RENDER,renderF);

services_mc.gotoAndPlay(1);

}

function release2(evt:MouseEvent):void {

this.addEventListener(Event.RENDER,renderG);

stage.invalidate();

this.gotoAndStop(30);

}

function renderG(e:Event):void{

this.removeEventListener(Event.RENDER,renderG);

services_mc.gotoAndPlay(16);

}

function release3(evt:MouseEvent):void {

this.addEventListener(Event.RENDER,renderH);

stage.invalidate();

this.gotoAndStop(30);

}

function renderH(e:Event):void{

this.removeEventListener(Event.RENDER,renderH);

services_mc.gotoAndPlay(31);

}

kglad
Community Expert
Community Expert
March 4, 2012

instead of that, consider:

var servicesFrameA:Array = [1,16,31];

var servicesFrame:int;

btn1.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn2.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn3.addEventListener(MouseEvent.MOUSE_UP, btnF);

function btnF(evt:MouseEvent):void {

servicesFrame = servicesFrameA[evt.currentTarget.name.substr(3)-1];

this.addEventListener(Event.RENDER,renderF);

stage.invalidate();

this.gotoAndStop(30);

}

function renderF(e:Event):void{

this.removeEventListener(Event.RENDER,renderF);

services_mc.gotoAndPlay(servicesFrame);

}

macneil2222作成者
Participating Frequently
March 4, 2012

I like it... so then it's a case of:

var servicesFrameA:Array = [1,16,31,46,61,76];

var servicesFrame:int;

btn1.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn2.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn3.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn4.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn5.addEventListener(MouseEvent.MOUSE_UP, btnF);

btn6.addEventListener(MouseEvent.MOUSE_UP, btnF);

function btnF(evt:MouseEvent):void {

servicesFrame = servicesFrameA[evt.currentTarget.name.substr(6)-1];

this.addEventListener(Event.RENDER,renderF);

stage.invalidate();

this.gotoAndStop(30);

}

function renderF(e:Event):void{

this.removeEventListener(Event.RENDER,renderF);

services_mc.gotoAndPlay(servicesFrame);

}

Thanks much

macneil2222作成者
Participating Frequently
March 4, 2012

Wow thanks to both of you.  I see how both will work and how to use them...

Many thanks!

Ned Murphy
Legend
March 4, 2012

What you would have to do is create a variable in frame 1 that you assign the value for mc2's frame and use that value when you get to frame 30.

mc2Frame = ??? some default value.

btn1.addEventListener(MouseEvent.MOUSE_UP, release1);

function release1(evt:MouseEvent):void {

    mc2Frame = 10;

    gotoAndPlay(30);

}

Then at frame 30 you would have...

mc2.gotoAndPlay(mc2Frame);

macneil2222作成者
Participating Frequently
March 4, 2012

Ned... Just trying to understand more... your way means that mc2Frame = 10; is only initiated from the button event?  So that any other time you get to frame 30 nothing happens? mc2.gotoAndPlay(mc2Frame); would get the default value otherwise?

Thanks again

Ned Murphy
Legend
March 4, 2012

Miy approach was assuming there is the possibility that you could go to other frames in mc2 when you get to frame 30.  If not, then you don't need to do anything as (mildly) complicated as what either kglad or I offered.... you would just need to put mc2.gotoAndPlay(10) in frame 30.

kglad
Community Expert
kgladCommunity Expert解決!
Community Expert
March 4, 2012

use:

btn1.addEventListener(MouseEvent.MOUSE_UP, release1);

function release1(evt:MouseEvent):void {

this.addEventListener(Event.RENDER,renderF);

stage.invalidate();

this.gotoAndPlay(30);

}

function renderF(e:Event):void{

this.removeEventListener(Event.RENDER,renderF);

mc2.gotoAndPlay(10);

}

kglad
Community Expert
Community Expert
March 4, 2012

there is a signficiant advantage to the code i suggested:  it keeps all your actionscript in one frame.

the disadvantage is that code is not intuitive and is therefore more difficult to understand.  but, if you can understand it, it's much better than adding code to other frames.