Skip to main content
Known Participant
September 14, 2010
Answered

Basic button script not working

  • September 14, 2010
  • 4 replies
  • 2430 views

well i lied it works at first but then it stops

I have a flash site that has a presentation page it has a menu of two buttons (1) to take you to a slide show and (2) that takes you to the gallery. these are the only two buttons that seem to work in control test movie, I get no errors.

The only button that is connected is the slideshow button (I havent done the gallery yet). This button takes you to frame two. where i have the main website. it has its own menu that spans across the entire website which is 25 frames. each frame represents a new page. i have mini menus at frames 3, 5, and ten. that are supposed to just advance the user to correct frame labels and stop.

here is my problem

the only buttons that work are the ones in the first frames.

the rollovers appear to work on all the pages when i advance the movie using the [ . ] key but i get no trace statement witch means that it is not being acknowledged, all my buttons are named properly i believe so i do not know what the problem is, here is the code as well, all is in frame one:

stop();

//handle events for buttons...

Gallery.addEventListener(MouseEvent.CLICK, clickSection);

Home.addEventListener(MouseEvent.CLICK, clickSection);

Location.addEventListener(MouseEvent.CLICK, clickSection);

Guest.addEventListener(MouseEvent.CLICK, clickSection);

Lodging.addEventListener(MouseEvent.CLICK, clickSection);

Cuisine.addEventListener(MouseEvent.CLICK, clickSection);

ExploreEcuador.addEventListener(MouseEvent.CLICK, clickSection);

Direction.addEventListener(MouseEvent.CLICK, clickSection);

Home.addEventListener(MouseEvent.CLICK, clickSection);

Lodging.addEventListener(MouseEvent.CLICK, clickSection);

Amenities.addEventListener(MouseEvent.CLICK, clickSection);

Hotel.addEventListener(MouseEvent.CLICK, clickSection);

Coast.addEventListener(MouseEvent.CLICK, clickSection);

BahiaDeCaraquez.addEventListener(MouseEvent.CLICK, clickSection);

CentralBankMuseum.addEventListener(MouseEvent.CLICK, clickSection);

IslaCorazon.addEventListener(MouseEvent.CLICK, clickSection);

RioChone.addEventListener(MouseEvent.CLICK, clickSection);

Beaches.addEventListener(MouseEvent.CLICK, clickSection);

CaboPasado.addEventListener(MouseEvent.CLICK, clickSection);

LaSegua.addEventListener(MouseEvent.CLICK, clickSection);

CerroSecoPark.addEventListener(MouseEvent.CLICK, clickSection);

WhaleWatching.addEventListener(MouseEvent.CLICK, clickSection);

SeasonalTours.addEventListener(MouseEvent.CLICK, clickSection);

HomePage.addEventListener(MouseEvent.CLICK, clickSection);

Contact.addEventListener(MouseEvent.CLICK, clickSection);

//end of menu

function clickSection(evtObj:MouseEvent) {

//trace shows what is happening.. in the output window

trace ("The "+evtObj.target.name+" button was clicked!")

//go to the section clicked on...

gotoAndStop (evtObj.target.name);

}

Help me Adobe-wan, you are my only hope...

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

If you have those buttons in different keyframes but only have code assigned to them in one ketframe, then the only ones that will work will be the ones in the coded keyframe. When you create new keyframes, you create new instances.

4 replies

June 13, 2020

Açıklama güzel yetersiz, benim gibi yeni başlamış biti için bu tuşları tek tek açıklar mısınız?

September 15, 2010

just a hint:
You can use less code that way maybe:

stage.addEventListener(MouseEvent.CLICK, clickSection);

function clickSection(evtObj:MouseEvent)
{

//trace shows what is happening.. in the output window

trace("The "+evtObj.target.name+" button was clicked!");

//go to the section clicked on...
try
{
  gotoAndStop(evtObj.target.name);
}
catch (err:Error)
{
}
}

Try it.

Hakan KIRIK - http://www.FlashDersi.com

Known Participant
September 15, 2010

I do not know what to say, but THANK YOU will have to suffice.

I do not know what motivated you to add an answer to an already resolved question, but THANK YOU, i was able to delete all the other code on all the different frames and just include that in the first frame and everything works perfectly. Thank you so much

YOURS WAS THE ANSWER I WAS LOOKING FOR

Known Participant
September 14, 2010

here is a link to the file it is 17mb

it will only be up for 24 hours

if someone could take a couple minutes to see why the buttons are not working.

http://EmailLargeFile.com/d/CPEOAX8$AIC

Ned Murphy
Ned MurphyCorrect answer
Legend
September 14, 2010

If you have those buttons in different keyframes but only have code assigned to them in one ketframe, then the only ones that will work will be the ones in the coded keyframe. When you create new keyframes, you create new instances.

Known Participant
September 14, 2010

I do not understand

i have the actions layers and it should span across all frames. and should control all the frames from one to twentytwo.

I attempted to put a new script on each of the key frames and i get error messages saying i had a duplicate function on line 36 (it says) =   function clickSection(evtObj:MouseEvent) {

I am sorry i am self taught so I do not know what to do to fix this.

Ned Murphy
Legend
September 14, 2010

You need to assign the event listeners in every frame where you have new button instances, but you cannot have functions with the same name.  Or have your buttons span the full timeline instead of creating new instances across the timeline.

Some code executes in the frame it is in, such as the event listeners you assign.  event listeners are only assigned to the instances that are present when it executes.   Some code sits in waiting, such as the event handler functions you create.  The functions will work across the timeline, so you don't need to duplicate them.

What I usually do is place frame-specific code (event listener assignments, function calls, etc) on a separate layer from than share-able code (vars, functions)