AS3- Buttons controlling timeline not working inside MovieClip

actionscript-3flashmovieclip

This is my first time coding a website using ActionScript. So far everything has went very well, I designed the website in Photoshop, and imported to Flash CS5. Then I cleaned everything up, and started adding navigation to the various pages using buttons.

The website is constructed in a very simple manner, there are five main pages and they are connected by buttons on a static navigation bar (the first page, home, doesn't have a corresponding button). Then there are nine sub pages, that each contain information on a character of the game, and are connected to corresponding buttons in the 'Character' layer/MovieClip. My four menu buttons (Story, The World, Characters, Extras) all navigate correctly without problems.

The problem arises because inside my Characters page (a movie clip) are nine buttons, each linking to a different page. These buttons should bring the timeline to the frame specified, but when the buttons are clicked nothing happens. I've spent hours searching for a solution to this, but with no avail, and I have a feeling the answer is pretty simple. Think you could help me out?

Here is what i've tried so far:

Replacing the

gotoAndStop("gowang", "Scene 1");

line in the Gowang character button function with:

MovieClip(root).gotoAndStop("gowang");

But this produced the same result, the buttons doing nothing.

I've also tried placing the character button listeners and functions inside the Character page MovieClip, but that gave me this error:

ArgumentError: Error #2108: Scene Scene 1 was not found.
at flash.display::MovieClip/gotoAndStop()
at Gowang_fla::Top_31/clickGowang()

I've spent a lot of time trying to fix this one, and I would really appreciate if someone could help.

~Here is the .FLA: http://mindsparkdesigns.com/files/WebsiteFla.zip

~Here is the code:

stop();

//Fade Effect

import fl.transitions.Tween;
import fl.transitions.easing.*;

var homeTween:Tween = new Tween(home_mc, "alpha", Regular.easeOut , 0, 1, 2, true);

//Buttons

story_btn.addEventListener(MouseEvent.CLICK, clickStory);
world_btn.addEventListener(MouseEvent.CLICK, clickWorld);
characters_btn.addEventListener(MouseEvent.CLICK, clickCharacters);
extras_btn.addEventListener(MouseEvent.CLICK, clickExtras);

home_mc.storyH_btn.addEventListener(MouseEvent.CLICK, clickStoryH);
home_mc.worldH_btn.addEventListener(MouseEvent.CLICK, clickWorldH);
home_mc.charactersH_btn.addEventListener(MouseEvent.CLICK, clickCharactersH);
home_mc.extrasH_btn.addEventListener(MouseEvent.CLICK, clickExtrasH);

top_mc.gowang_btn.addEventListener(MouseEvent.CLICK, clickGowang);
top_mc.ayame_btn.addEventListener(MouseEvent.CLICK, clickAyame);
top_mc.evora_btn.addEventListener(MouseEvent.CLICK, clickEvora);
top_mc.rogin_btn.addEventListener(MouseEvent.CLICK, clickRogin);
top_mc.toraz_btn.addEventListener(MouseEvent.CLICK, clickToraz);
top_mc.naomi_btn.addEventListener(MouseEvent.CLICK, clickNaomi);
top_mc.rummy_btn.addEventListener(MouseEvent.CLICK, clickRummy);
top_mc.teeth_btn.addEventListener(MouseEvent.CLICK, clickTeeth);
top_mc.sichan_btn.addEventListener(MouseEvent.CLICK, clickSichan);

extras_mc.blog_btn.addEventListener(MouseEvent.CLICK, clickBlog);

function clickBlog(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.gowangadventures.blogspot.com"), "_blank");
}

function clickGowang(evtObj:MouseEvent){
gotoAndStop("gowang", "Scene 1");
}
function clickAyame(evtObj:MouseEvent){
gotoAndStop("ayame", "Scene 1");
}
function clickEvora(evtObj:MouseEvent){
gotoAndStop("evora", "Scene 1");
}
function clickRogin(evtObj:MouseEvent){
gotoAndStop("rogin", "Scene 1");
}
function clickToraz(evtObj:MouseEvent){
gotoAndStop("toraz", "Scene 1");
}
function clickNaomi(evtObj:MouseEvent){
gotoAndStop("naomi", "Scene 1");
}
function clickRummy(evtObj:MouseEvent){
gotoAndStop("rummy", "Scene 1");
}
function clickTeeth(evtObj:MouseEvent){
gotoAndStop("teeth", "Scene 1");
}
function clickSichan(evtObj:MouseEvent){
gotoAndStop("sichan", "Scene 1");
}
function clickStory(evtObj:MouseEvent){
gotoAndStop("story");
}
function clickWorld(evtObj:MouseEvent){
gotoAndStop("world");
}
function clickCharacters(evtObj:MouseEvent){
gotoAndStop("characters");
}
function clickExtras(evtObj:MouseEvent){
gotoAndStop("extras");
}
function clickStoryH(evtObj:MouseEvent){
gotoAndStop("story", "Scene 1");
}
function clickWorldH(evtObj:MouseEvent){
gotoAndStop("world", "Scene 1");
}
function clickCharactersH(evtObj:MouseEvent){
gotoAndStop("characters", "Scene 1");
}
function clickExtrasH(evtObj:MouseEvent){
gotoAndStop("extras", "Scene 1");
}

Best Answer

It looks like you're assigning button listeners to buttons that aren't on the stage at the point you're declaring them. Move this code below your tween code on frame 30 and it should work:

top_mc.gowang_btn.addEventListener(MouseEvent.CLICK, clickGowang);
top_mc.ayame_btn.addEventListener(MouseEvent.CLICK, clickAyame);
top_mc.evora_btn.addEventListener(MouseEvent.CLICK, clickEvora);
top_mc.rogin_btn.addEventListener(MouseEvent.CLICK, clickRogin);
top_mc.toraz_btn.addEventListener(MouseEvent.CLICK, clickToraz);
top_mc.naomi_btn.addEventListener(MouseEvent.CLICK, clickNaomi);
top_mc.rummy_btn.addEventListener(MouseEvent.CLICK, clickRummy);
top_mc.teeth_btn.addEventListener(MouseEvent.CLICK, clickTeeth);
top_mc.sichan_btn.addEventListener(MouseEvent.CLICK, clickSichan);

Since your 'characters_mc' is on the stage at that frame, they're available to accept those listeners (since they didn't exist when you tried declaring them before).

Related Topic