Skip to main content
Participant
October 17, 2009
Answered

help with nav buttons please

  • October 17, 2009
  • 1 reply
  • 743 views

Hey there, i've recently been following a tutorial and I have come across a problem with the AS for the nav buttons,  http://www.flash-game-design.com/flash-tutorials/basic-flash-website-tutorial-6.html, the tutorial says to write:

btnabout.onRelease = function(){
    content.gotoAndStop("about")
}
btnport.onRelease = function(){
    content.gotoAndPlay("port")
}
btncont.onRelease = function(){
    content.gotoAndStop("contact")
}

I have done this and it came with an error saying needs to be in handler, so i re-entered this:

btnabout.on(release) = function(){
    content.gotoAndStop("about")
}
btnport.on(release) = function(){
    content.gotoAndPlay("port")
}
btncont.on(release) = function(){
    content.gotoAndStop("contact")
}

This code then came back with a Expected a field name after '.' operator.  btnabout.on(release) = function(){ can anyone please help me i'm starting to pull hairs out?!

Thanks

P.S it must be AS 2.0 as that is what my portfolio page uses.

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

The problem with the first attempt was not the code, but where you placed it.  That code needs to be placed on the timelinein the same frame as where the buttons are  (preferably in a separate 'actions' layer).  This approach is the better approach than trying to place the code on the objects because it keeps all code in a single easy to find location... the timeline.

For the second attempt, assuming you were still trying to attach the code to the buttons, you should change the code to....

on(release) {
    content.gotoAndStop("about")
}

on(release){
    content.gotoAndPlay("port")
}


on(release){
    content.gotoAndStop("contact")
}

but.... each of those needs to be attached to the button associated with it and not grouped together.  This is an older style of coding that is best avoided due to ending up with code hiding on objects.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
October 17, 2009

The problem with the first attempt was not the code, but where you placed it.  That code needs to be placed on the timelinein the same frame as where the buttons are  (preferably in a separate 'actions' layer).  This approach is the better approach than trying to place the code on the objects because it keeps all code in a single easy to find location... the timeline.

For the second attempt, assuming you were still trying to attach the code to the buttons, you should change the code to....

on(release) {
    content.gotoAndStop("about")
}

on(release){
    content.gotoAndPlay("port")
}


on(release){
    content.gotoAndStop("contact")
}

but.... each of those needs to be attached to the button associated with it and not grouped together.  This is an older style of coding that is best avoided due to ending up with code hiding on objects.

Participant
October 17, 2009

Umm I think I have already done that, Heres a screen shot of what i've got. Sorry I only really know basicas of AS.

Thanks

Ned Murphy
Legend
October 17, 2009

There's no telling what you did by that picture, but you said you got an error regarding it needing to be in a handler which indicates you were trying to place that code on an object and not in the timeline where it is supposed to go.  The second bit of code you showed/tried is just wrong, so you should forget that altogether.  The way I showed the code is the way is needs to be done when you place the code on the object(s)... each getting its own placed on it... in that case you do not use the actions layer.

You'll need to choose one approach or the other and then indicate how you have it implemented if you still cannot get it to work.