PDA

View Full Version : problem navigating timeline



fherrmann
March 26th, 2009, 10:57 AM
I am really new to actionscript 3 and am having some trouble wrapping my brain around this. I have what basically amounts to a slideshow with navigation. I have a menu frame that has buttons, that when clicked, move across the timeline to a specific frame and stops.

http://www.frankswebdev.com/timeline.jpg

From there the navigation has 3 buttons..."menu" (goes back to menu) and "previous" and "next" which have actions associated with it to go to next frame or previous frame. I have an actions layers that has the code in it and it works fine from the menu (attached is the menu actionscript) as long as I click on the item that is on the keyframe directly under the keyframe containing the actionscript. How can I get the frames that aren't directly under the actionscript frame to use the actions?

Attached is the code for the menu keyframe and the slides beyond it


/////////////////////////////////////////// code for the menu keyframe on it's own actions layer
stop();
import flash.events.MouseEvent;

btnShoulder.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void
{
gotoAndStop(41)

}

btnWrist.addEventListener(MouseEvent.CLICK, onClick2);

function onClick2(event:MouseEvent):void
{
gotoAndStop(50)

}

btnKnee.addEventListener(MouseEvent.CLICK, onClick3);

function onClick3(event:MouseEvent):void
{
gotoAndStop(44)

}

btnAdvantage.addEventListener(MouseEvent.CLICK, onClick4);

function onClick4(event:MouseEvent):void
{
gotoAndStop(52)

}




////////////////////////////////// actions for the frames beyond the menu frame

stop();
import flash.events.MouseEvent;


btnMenu.addEventListener(MouseEvent.CLICK, onClick6);

function onClick6(event:MouseEvent):void
{
gotoAndStop(40);

}

btnPrevious.addEventListener(MouseEvent.CLICK, goBack);
btnNext.addEventListener(MouseEvent.CLICK, goForward);

function goBack(event:MouseEvent):void {


if (currentFrame == 40)
{
stop();
}
else
{
this.prevFrame();
}



}
function goForward(event:MouseEvent):void {

if (currentFrame == 52)
{
stop();
}
else
{
this.nextFrame();
}
}


var lc:LocalConnection = new LocalConnection();

btnClose.addEventListener(MouseEvent.CLICK, closeMe, false, 0, true);

function closeMe(e:MouseEvent): void {

btnClose.removeEventListener(MouseEvent.CLICK, closeMe);

lc.send("lcClient","closeBio");
}

i11uminatus
March 26th, 2009, 12:11 PM
It would seem to me that your problem is with the keyframes in the button layer. This is a fairly consistent problem that I see when people mix programming concepts from "old" Flash and the scripting styles of "new" Flash. Since you say you're new to Actionscripting I will try to explain. I'm sure if I make any mistakes someone will correct me.

When your menu script runs it assigns event listeners to instances of buttons on the stage. Those button instances only live in that one keyframe, however. When you change keyframes you are getting new instances of those objects, even if they are the same symbol, same instance name, same position... doesn't matter. It's a brand new object as far as the script is concerned and has no connection to the script that you had applied previously.

You could handle this a couple of ways:
1) repeat the script assignment. Every time you change keyframes, re-assign the event listeners to the objects. This has the potential to get a little sloppy.
2) remove the keyframes. This is what I tend to do. I put ALL the buttons I'm going to need in one keyframe that persists for the entire duration of that section of your movie (or on separate layers, if you need help managing them). Then I switch their .visible property on or off depending on whether I want to show that button or not at any given time.

Hope this is helpful to you.

fherrmann
March 27th, 2009, 10:50 AM
I removed all the keyframes for the buttons and actions but still can't get the thing to work for the items that aren't directly below the keyframe with the actionscript. I'll keep tinkering I guess to see if I can figure it out.