【问题标题】:Need Help with animation gallery in AS3在 AS3 中需要有关动画库的帮助
【发布时间】:2010-08-19 17:19:08
【问题描述】:

我一直在尝试用不同的影片剪辑在 Flash 中创建一个画廊。

Timeline
-back button
-next button
-stop button
-play button 
-Main Movie
 (these are inside Main Movie)
 --Animation 1
 --Animation 2
 --Animation 3

我在 Main Movie 中设置了动画,其实例名称和帧名称如“Animation 1”。我让它播放和停止,但我不能用后退和下一个按钮来回浏览每个动画。什么是我可以解决这个问题的正确方法?

---2010 年 8 月 20 日更新

我让它工作了,但是有一个小错误。每当我单击下一步或后退按钮时,它都会转到第一个帧名称,然后是另一个。我进行了跟踪,发现它计数“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); 
}

【问题讨论】:

  • 你能提供更多细节吗?请告诉我你期望的行为和你实际得到的行为
  • 抱歉耽搁了,我被困在医生办公室,明天就生病了。我试图做的是当你开始 Flash 电影时,第一个动画开始,如果你点击下一个按钮,你会转到第二个动画,当你到达最后一个动画时,它会回到第一个动画,同样为背面在反面。我希望有帮助。再次抱歉,如果我说得不对。我一直感觉不舒服。 :(
  • 对不起,我现在才看到你的评论!我已经编辑了代码,所以它应该可以按预期工作,但我看到你也找到了解决方案。抱歉回复延迟!

标签: flash actionscript-3


【解决方案1】:

您应该将以下代码放在按钮所在的主时间轴上。我已将实例名称“main”赋予您的 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);
  }

创建一个变量来注册当前动画并减少或增加它以返回或播放下一个动画。使用 MouseEvent 侦听器将相关功能分配给按钮。这里我使用了 1 和 3,但你可以有几个变量,minAnimIndex 和 maxAnimIndex。

希望这会有所帮助!

【讨论】:

  • 感谢您的帮助,我正在尝试。我唯一的问题是当我为当前动画分配变量时,你说的是把它放在“主电影”中吗?
  • 是的,它应该与动画处于同一级别,否则您将不得不执行类似的操作:instanceName.gotoAndStop(frameName);表示从动画所在的 MovieClip 调用方法
  • 我想我已经知道了。我在电影的动画中加入了“currentAnimationIndex”和“currentAnimation”,但脚本中不断出现此错误。 1046:类型未找到或不是编译时常量:playNext.
【解决方案2】:

了解如何在 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-12-13
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    相关资源
    最近更新 更多