Need Help with animation gallery in AS3
I been trying to create a gallery in Flash with different movie clips.
Timeline
-back button
-next button
-stop button
-play button
-Main Movie
(these are inside Main Movie)
--Animation 1
--Animation 2
--Animation 3
I have the animations set up in Main Movie with instance name and frame names like "Animation 1". I got it to play and stop, but I can't go back and forth through each animations with the back and next buttons. What's the right way I can pull this off?
---Update 8-20-2010
I got it to work, but with a tiny bug. Whenever I click the next or back buttons it goes to the first frame name then the other. I did a trace and I found it counting "ad-1, ad-2, ad-3, etc.." or "ad1, ad2, ad3, etc.."
var currentAnimationIndex:int;
var currentAnimation:int;
var animeOstart:Number = 1;
var animeOend:Number = 3;
function playAnimation(frameIndex:int):void
{
var frameName:String = "ad" + frameIndex.toString();
trace(frameName)
ads.gotoAndPlay(frameName);
ads.movie.gotoAndPlay(1);
currentAnimationIndex = frameIndex;
}
function playBack(event:MouseEvent):void
{
--currentAnimationIndex;
i开发者_运维知识库f(currentAnimationIndex < animeOstart)
currentAnimation == 1;
playAnimation(currentAnimationIndex);
}
function playNext(event:MouseEvent):void
{
++currentAnimationIndex;
if(currentAnimationIndex > animeOend)
currentAnimation == 3;
playAnimation(currentAnimationIndex);
}
You should place the following code on the main Timeline , where the buttons are. I've given the instance name "main" to your Main MovieClip.
var currentAnimationIndex:int;
public function playAnimation(frameIndex:int):void
{
var frameName:String = "Animation " + frameIndex.toString();
main.gotoAndStop(frameName);
currentAnimationIndex = frameIndex;
}
public function playBack(event:MouseEvent):void
{
--currentAnimationIndex;
if(currentAnimationIndex < 1)
currentAnimation == 3;
playAnimation(currentAnimationIndex);
}
public function playNext(event:MouseEvent):void
{
++currentAnimationIndex;
if(currentAnimationIndex > 3)
currentAnimation == 1;
playAnimation(currentAnimationIndex);
}
Create a variable that registers the current animation and decrement it or increment it to go back or to play the next animation. Assign the relevant function to the button with a MouseEvent listener. Here I have used 1 & 3 but you could have a couple of variables, minAnimIndex & maxAnimIndex.
Hope this helps!
Found out how to do it in AS3!!!!
b_back.addEventListener(MouseEvent.CLICK, prevSection);
b_next.addEventListener(MouseEvent.CLICK, nextSection);
function nextSection(event:MouseEvent):void {
var thisLabel:String = ads.currentLabel; // gets current frame label as string
var thisLabelNum:String = thisLabel.replace("ad", ""); // cuts the leading letters off of the number
var curNumber:Number = Number(thisLabelNum); // converts that string number to a real number
if (curNumber < 3) {
var nextNum:Number = curNumber + 1; // adds 1 to the number so we can go to next frame label
ads.gotoAndPlay("ad" + nextNum); // This allows us to go to the next frame label
}else if(curNumber >= 3){
ads.gotoAndPlay("ad" + 1); // This allows us to go to the next frame label
}
}
function prevSection(event:MouseEvent):void {
var thisLabel:String = ads.currentLabel; // gets current frame label as string
var thisLabelNum:String = thisLabel.replace("ad", ""); // cuts the leading letters off of the number
var curNumber:Number = Number(thisLabelNum); // converts that string number to a real number
var prevNum:Number = curNumber - 1; // subtracts 1 from the number so we can go to next frame label
ads.gotoAndPlay("ad" + prevNum); // This allows us to go to the previous frame label*/
if (curNumber == 1) {
ads.gotoAndPlay("ad" + 3); // This allows us to go to the next frame label
}
}
found it from this site. http://www.developphp.com/Flash_tutorials/show_tutorial.php?tid=161
精彩评论