我一直试图在Flash中创建一个不同的电影剪辑画廊。
Timeline
-back button
-next button
-stop button
-play button
-Main Movie
(these are inside Main Movie)
--Animation 1
--Animation 2
--Animation 3我有动画设置在主电影与实例名称和帧名称,如“动画1”。我让它播放和停止,但我不能通过后退和下一步按钮来回切换每个动画。我做这件事的正确方法是什么?
-更新8-20-2010
我让它工作了,但有一个很小的bug。每当我单击“下一步”或“后退”按钮时,它都会转到第一个框架名称,然后是另一个。我做了一个跟踪,我发现它在计算"ad-1,ad-2,ad-3,等等“。或"ad1、ad2、ad3等。“
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;
if(currentAnimationIndex < animeOstart)
currentAnimation == 1;
playAnimation(currentAnimationIndex);
}
function playNext(event:MouseEvent):void
{
++currentAnimationIndex;
if(currentAnimationIndex > animeOend)
currentAnimation == 3;
playAnimation(currentAnimationIndex);
}发布于 2010-08-23 22:36:29
了解了如何在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
}
}在这个网站上找到的。http://www.developphp.com/Flash_tutorials/show_tutorial.php?tid=161
发布于 2010-08-20 01:33:14
您应该将下面的代码放在按钮所在的主时间轴上。我已经为你的主MovieClip指定了实例名" Main“。
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);
}创建一个注册当前动画的变量并递减它,或者递增它以返回或播放下一个动画。将相关函数分配给具有MouseEvent侦听器的按钮。这里我使用了1和3,但是你可以有几个变量,minAnimIndex和maxAnimIndex。
希望这能有所帮助!
https://stackoverflow.com/questions/3524391
复制相似问题