Hi, I've been using AS2 in CS3 for a few months and have been travelling OK.
I just updated to CS4 as I want to use some of the cool new features, but must use AS3 in order to do so. AS3 has got me totally lost! (bloody frustrating! - I'm used to attaching script to buttons).
Problem: I an setting up a presentation where the user presses a button to go to the next frame or previous frame.
My method:
I have a button placed on frame 1 called fwd.
I have a button on frames 2 to 100 called advance, (one keyframe).
I have this same script across all frames:
fwd.addEventListener(MouseEvent.MOUSE_UP,goforward);
function goforward(event:MouseEvent):void
{
nextFrame();
}
advance.addEventListener(MouseEvent.MOUSE_UP,stepforward);
function stepforward(event:MouseEvent):void
{
nextFrame();
Result, it will step forward to the next frame, but no more. (fwd button only works once, and advance button does not work at all).
Can someone please tell me where I'm going wrong?
Surely I don't have to program actions for all 300 something buttons?
AS3 - Simple problem with buttons?I'm sharing what I've learned in this forum. You said you have two buttons on stage.
Follow these steps:
one button named nextBtn the other backBtn.
This script goes in frame 1 and will work for six frames. Each frame is labeled section1, section2, ect.
stop();
backBtn.visible=false;
nextBtn.addEventListener(MouseEvent.CLICK, goNextSection);
backBtn.addEventListener(MouseEvent.CLICK, goPreviousSection);// USE THIS LISTENER TO GO BACK
function goNextSection(event:MouseEvent):void
{
var thisLabel:String= currentLabel;
var thisLabelNum:String = thisLabel.replace(''section'', '''');
var curNumber:Number = Number(thisLabelNum);
if (curNumber %26lt;6)
{
?var nextNum:Number = curNumber+1;
?gotoAndStop(''section'' + nextNum);
}
}//end function next
USE THIS SCRIPT IF YOU PLAN TO GO BACK
function goPreviousSection (event:MouseEvent): void
{
var thisLabel:String = currentLabel;
var thisLabelNum:String = thisLabel.replace (''section'', '''');
var curNumber:Number = Number(thisLabelNum);
var prevNum:Number = curNumber-1;
if (thisLabel== ''section1''){prevNum=curNumber}
gotoAndStop(''section'' + prevNum);
?
}// end function
good luck!
AS3 - Simple problem with buttons?Thanks German01 for your assistance, but I solved it (I think!).
I wrongly understood that the script for all interface assets in AS3 is placed in it's own frame at frame 1.
No, it appears that the event handling text is written at the frame/s where that interface is placed.
I'm thankful to see my first ever forum entry was answered. At least that gives me hope.
Cheers.
No comments:
Post a Comment