首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要在AS3中使用动画库的帮助

需要在AS3中使用动画库的帮助
EN

Stack Overflow用户
提问于 2010-08-20 01:19:08
回答 2查看 309关注 0票数 0

我一直试图在Flash中创建一个不同的电影剪辑画廊。

代码语言:javascript
复制
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等。“

代码语言:javascript
复制
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); 
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-08-23 22:36:29

了解了如何在AS3中完成此操作!

代码语言:javascript
复制
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

票数 0
EN

Stack Overflow用户

发布于 2010-08-20 01:33:14

您应该将下面的代码放在按钮所在的主时间轴上。我已经为你的主MovieClip指定了实例名" Main“。

代码语言:javascript
复制
  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。

希望这能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3524391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档