分阶段创建复杂的Flash翻转(循环>翻转动画>定时动画)

时间:2012-01-24 17:36:25

标签: flash actionscript-3

好的,现在事情变得有点复杂了。 我需要构建一个Flash对象,它可以位于图像的角落以提供额外的内容。 这超出了我的Flash技能水平,我的工作通常仅限于在Photoshop和Illustrator中进行打印,所以如果以下任何一项不清楚,请原谅我。我试图学习,所以任何正确方向的指针都会非常感激。

所以这就是它应该如何工作,以及我的问题;

  1. 当图像& Flash项目加载一个小的循环动画将播放画眼/显示项目为交互式。 当用户翻过来时,角落会剥落。我有一个工作的剥离动画用于翻转,对鼠标悬停/鼠标关闭做出反应,并为初始设置循环动画,但我无法弄清楚如何在鼠标悬停之前进行初始循环,然后在鼠标结束时播放剥离。如果用户滚动,请返回初始动画循环。 (这些动画中的每一个都作为影片剪辑存储在库中)

  2. 然后它会变得更复杂......如果用户停留在角落直到完全剥离,我需要做一个小的倒计时(有点像3,2,1的情况)节目,然后再启动在浏览器中,灯箱(这必须是jQuery,还是可以在Flash中完成?)来提供内容。

  3. 感谢任何人提供的任何帮助,以及任何部分。就像我说的,我正在尽力学习,所以任何解释都会非常感激!

1 个答案:

答案 0 :(得分:0)

更新:根据OP的评论,下面概述了一个新的建议解决方案。

我已经在下面写了一个改进的(但未经测试的)解决方案。由于你是一个相对较新的Flash,我添加了一些小“弯路”,我希望能澄清ActionScript 3的各个部分是如何工作的,特别是在事件处理方面。

重新开始,这是我设置主要FLA时间轴的方式:

  1. 在主时间轴上创建4个图层 - 操作,热点,循环和卷曲,按顺序从上到下
  2. 在热点图层上,创建一个覆盖剪辑“鼠标”区域的矩形。将矩形的颜色设置为alpha = 0并删除它具有的任何边框。然后将其转换为MovieClip符号并将舞台实例命名为“hotspot_mc”。
  3. 将循环MovieClip放在循环图层上,并将其命名为“loop_mc”。
  4. 将curl MovieClip放在curl图层上,并将其命名为“curl_mc”。
  5. 沿着以下行添加代码到actions图层的第一个关键帧:

  6. import flash.external.ExternalInterface;
    import flash.events.MouseEvent;
    import flash.events.Event;
    
    //Stops the main timeline on the first frame
    stop();
    
    //Makes the curl_mc invisible
    //(Note: alpha varies from 0 to 1, so for instance you can make any 
    //clip half-transparent by typing clipName.alpha = 0.5)
    curl_mc.alpha = 0;
    
    //Stop the curl_mc clip from playing initially, we only want it to begin 
    //playing on rollover
    curl_mc.stop();
    
    //Make your hotspot look like a button when users mouse over it
    //by setting these properties on it
    hotspot_mc.useHandCursor = true;
    hotspot_mc.buttonMode = true;
    
    //We attach our event handlers to the hotspot.  Because the hotspot is a 
    //rectangle of specific position and size it lets us control exactly where 
    //mouse actions will trigger events.  You *could* attach the handlers to 
    //loop_mc instead, so a hotspot clip isn't strictly necessary, but it's 
    //handy.  You can also make the shape in the hotspot_mc any shape you 
    //want, it does not need to be a rectangle.
    
    hotspot_mc.addEventListener(MouseEvent.ROLL_OVER, onLoopRollover, false, 0, true);
    hotspot_mc.addEventListener(MouseEvent.ROLL_OUT, onLoopRollout, false, 0, true);
    
    //Lastly, to be extra fancy, let's trigger your lightbox when 
    //the user clicks the hotspot OR when the curl_mc dispatches 
    //the 'curlComplete' event (which you will set up yourself on 
    //the last frame of the curl_mc timeline).
    
    hotspot_mc.addEventListener(MouseEvent.CLICK, showLightbox, false, 0, true);
    curl_mc.addEventListener('curlComplete', showLightbox, false, 0, true);
    
    //When we roll over the hotspot, hide the loop and show the curl
    function onLoopRollover(e:MouseEvent):void
    {
      //Hide the loop animation so we can see the curl beneath it
      loop_mc.alpha = 0;
      loop_mc.stop();
    
      //Show the curl animation and play it
      curl_mc.alpha = 1;
      curl_mc.gotoAndPlay(1);
    }
    
    //When we roll out of the hotspot, hide the curl and show the loop
    function onLoopRollout(e:MouseEvent):void
    {
      loop_mc.alpha = 1;
      loop_mc.gotoAndPlay(1);
    
      curl_mc.alpha = 0;
      curl_mc.stop();
    }
    
    //Shows the JavaScript-based lightbox
    function showLightbox(e:Event = null):void
    {
      ExternalInterface.call('JS_ShowLightbox');
    }
    

    ...最后,在curl_mc时间轴的最后一帧(在倒计时序列之后),将此代码添加到该时间轴的动作层上的关键帧:

    import flash.events.Event;
    dispatchEvent(new Event('curlComplete'));
    stop();
    
    
    //dispatchEvent() is a function that sends an event out to be 
    //handled by any listening handler functions (like the ones on 
    //frame 1 of the main timeline).  dispatchEvent() accepts an Event 
    //as a parameter, which we create new for this purpose.  In turn, 
    //when creating a new Event, you pass in the name of the event so 
    //that handlers can tell them apart.  This matches the event name 
    //passed in to addEventListener(eventName, eventHandler, false, 0, true).
    
    //This is how event handlers basically work in AS3.  By putting this 
    //code on the last frame of curl_mc, we use a new event to signal to 
    //our application that the curl animation is done.
    

    当然,编码这种情况不仅仅是这种方式。但是,通过这种方法,您可以了解如何从应用程序的某个区域创建和“分派”事件,并通过在不同位置编写的函数来处理它们。

    HTH!

    原始回答

      

    我无法弄清楚如何在鼠标悬停之前进行初始循环,然后在鼠标结束时播放剥离。如果用户滚动,请返回初始动画循环。

    使用ActionScript函数gotoAndPlay()和gotoAndStop()。

    您可以使用这两个功能来创建循环并控制动画的播放。例如,如果您创建了一个关键帧,请选择它,然后打开“操作”窗口,您可以添加此ActionScript:

    gotoAndPlay(1);
    

    一旦播放头到达此关键帧,时间线将跳转到第1帧并播放。这将创建从第1帧到关键帧的无限播放循环。每次播放头击中此关键帧时,它都会跳回并重新启动。

    如果在时间轴上定义了帧标签,也可以使用它们,例如:

    gotoAndPlay('rolloverStart');
    

    gotoAndStop()以相同的方式工作,除了它将跳转到给定的帧并在那里停止动画。

      

    如果用户停留在角落直到完全剥离,我需要在启动灯箱之前做一个小倒计时(有点像3,2,1的情况)节目(这必须是jQuery,还是可以它可以在Flash中完成吗?)在浏览器中提供内容。

    为了澄清,有两个功能要执行:

    1. 当用户将鼠标悬停在角落(“热点”)上时,辅助动画将开始播放并在完成后执行操作

    2. Flash必须在网页上引发灯箱

    3. Re:功能#1,我能想到的最简单的方法是在倒车动画结束时添加倒计时动画。这有效地创建了一个长翻转动画,最后有一个动作。

      Re:功能#2,你可以用Flash来调用Javascript函数,包括一个会显示灯箱的函数。在倒计时动画结束时,您可以添加关键帧并使用此ActionScript 3代码:

      import flash.external.ExternalInterface;
      ExternalInterface.call('JS_ShowLightbox');
      

      如果您的网页中有一个名为JS_ShowLightbox()的Javascript函数,则会在Flash到达此关键帧时调用它。

      HTH,

      罗斯

相关问题