Skip to main content
Inspiring
January 30, 2010
Answered

Making my script work when the MC is inside a scrollpane

  • January 30, 2010
  • 1 reply
  • 480 views

Im using the following script in the main timeline frame and I've got many buttons inside the buttons_mc.How do I change this script to make a button which is inside the buttons_mc work with a scrollpane.

dparty1.addEventListener(MouseEvent.CLICK, releaseone1);
function releaseone1(evt:MouseEvent):void {
gotoAndPlay(45);
}

This topic has been closed for replies.
Correct answer Ned Murphy

For the code below, this is the scenario:

1) two button symbols with instance names btn1 and btn2 are placed inside a movieclip that has a linkage ID of MC.

2) there is a scrollpane on the stage with an instance name sp

3) The code below is placed on the main timeline (or whatever timeline sp is in).  This way, the buttons' code can directly address the main timeline to do something.

sp.source = "MC"; // place the movieclip in the scrollpane

var menuClip:Object = sp.content; // get a target for the MC inside sp

// add event listeners/handler functions to the buttons in the MC inside the sp

menuClip.btn1.addEventListener(MouseEvent.CLICK, btn1Click);
menuClip.btn2.addEventListener(MouseEvent.CLICK, btn2Click);

function btn1Click(evt:MouseEvent):void {
      gotoAndPlay(45);
}

function btn2Click(evt:MouseEvent):void {
     trace("btn2 clicked");
}

1 reply

Inspiring
January 30, 2010

I think my english is not good enough. Sorry about that! I'll try to explain again.

How to make a button inside a scrollpane work?

E.g.

To goto the New Zealand map I should goto the 45th frame in the main timeline.

How do I write the code for a button inside a scrollpane to do that?

Ned Murphy
Ned MurphyCorrect answer
Legend
January 30, 2010

For the code below, this is the scenario:

1) two button symbols with instance names btn1 and btn2 are placed inside a movieclip that has a linkage ID of MC.

2) there is a scrollpane on the stage with an instance name sp

3) The code below is placed on the main timeline (or whatever timeline sp is in).  This way, the buttons' code can directly address the main timeline to do something.

sp.source = "MC"; // place the movieclip in the scrollpane

var menuClip:Object = sp.content; // get a target for the MC inside sp

// add event listeners/handler functions to the buttons in the MC inside the sp

menuClip.btn1.addEventListener(MouseEvent.CLICK, btn1Click);
menuClip.btn2.addEventListener(MouseEvent.CLICK, btn2Click);

function btn1Click(evt:MouseEvent):void {
      gotoAndPlay(45);
}

function btn2Click(evt:MouseEvent):void {
     trace("btn2 clicked");
}

Inspiring
February 2, 2010

Thank you NedMurphy.