0

我正在尝试构建一个用按键控制的通用幻灯片放映 Flash 文件...向右和向左箭头转到下一张/上一张幻灯片,向下和向上调用/取消调用单个动画/项目符号点/单张幻灯片上的任何内容. 到目前为止,我设法获得了一个文件,该文件可以从影片剪辑中加载所有页面,并使用左右箭头轻拂它们,并具有很好的淡出和淡入效果,即使在非常快地轻弹时也是如此。经过几个小时和大量谷歌搜索后,我根本没有得到什么是现在如何控制单页电影剪辑。到目前为止,我上传了文件:

http://www.broesel-brzelius.de/zeug/slide.zip

您可以看到我(到目前为止还很粗糙)尝试将 pageHolder.Pages.page1 影片剪辑控制到 gotoAndStop(2) 只会导致加载到数组中位置 0 的 pageHolder.Pages 影片剪辑转到第 2 帧,因此显示第二页。

到目前为止的代码:

import flash.display.Sprite; 
import flash.events.MouseEvent; 
import com.greensock.*; 
import flash.display.MovieClip; 

// instantiate a variable to find number of pages 
var numberOfPages:Pages = new Pages(); 
// instantiate an array to hold the page movieclips 
var pageArray:Array = new Array(); 
// instantiate a container to hold the pages 
var pageHolder:Sprite = new Sprite(); 
// declare variables that will hold reference to the current page IDs
var targetIDold:int = 0;
var targetIDnew:int = 0;
// declare a variable that will hold the current direction of slide movement
var movement:int = -1;

// call a function that builds the application 
// pass in the number of pages in fl_prevSlide 
buildApp(numberOfPages.totalFrames);

// this function builds the application
function buildApp(n:int):void
{
    // declare variables for the pages
    var p:Pages;
    // instantiate a new Page, send its playhead to the current value of i+1
    // it is necessary to add 1 to the value of i, since i starts at 0, while the timeline starts at 1
    for (var i:int = 0; i < n; i++) 
    { 
        p = new Pages(); 
        p.gotoAndStop(i + 1); 
        pageArray.push(p);
    } 
    // set the position of the pageHolder relative to the buttonHolder 
    pageHolder.x = pageHolder.y = 0; 
    // add the first page (at index 0) from pageArray to pageHolder 
    pageHolder.addChild(pageArray[targetIDnew]); 
    // add pageHolder and buttonHolder to the stage 
    addChild(pageHolder); 
} 

//Adding Listener and corresponding function to change between slides
stage.addEventListener(KeyboardEvent.KEY_DOWN, f_changeSlide);
function f_changeSlide(evt:KeyboardEvent):void
{
    if(evt.keyCode == 37) // left arrow
    {
        f_prevSlide();
    }
    else if (evt.keyCode == 39 || evt.keyCode == 32) // right arrow or space
    {
        f_nextSlide();
    }
}
function f_prevSlide():void
{
    if(targetIDnew > 0)
    {
        movement = -1;
        targetIDnew -= 1;
        f_addPage();
    }
}
function f_nextSlide():void
{
    if(targetIDnew < (numberOfPages.totalFrames - 1))
    {
        movement = 1;
        targetIDnew += 1;
        f_addPage();
    }
}

function f_addPage():void 
{ 
    // use the targetID variable to access the corresponding index in the pageArray and assign it to a temporary variable
    targetIDold = targetIDnew - movement;
    var _mcOld:MovieClip = MovieClip(pageArray[targetIDold]);
    var _mcNew:MovieClip = MovieClip(pageArray[targetIDnew]);
    //avoid flickering
    if (_mcNew.alpha == 1) {
        _mcNew.alpha = 0;
    }
    // add the temp variable to pageHolder
    pageHolder.addChild(_mcNew);
    // tween the temp variable to the specified properties, then call a function to remove the previous page
    // new page gets faded in, old page gets faded out
    TweenMax.to(_mcNew, 1.5, {alpha:1}); 
    TweenMax.to(_mcOld, 1.5, {alpha:0, onComplete:f_removePage}); 
} 

function f_removePage():void 
{ 
    // previous page will always be at index 0; remove it 
    // the new page just added will drop down to index 0 when the previous page is removed 
    pageHolder.removeChildAt(0); 
}

//Trying to advance / decrease the timeline in the movieclips of the single pages by pressing down / up
stage.addEventListener(KeyboardEvent.KEY_DOWN, f_changeFrame);
function f_changeFrame(evt:KeyboardEvent):void
{
    if(evt.keyCode == 40) // down arrow
    {
        f_nextFrame();
    }
    else if (evt.keyCode == 38) // up arrow
    {
        f_prevFrame();
    }
}
function f_nextFrame():void
{
        var w:uint = pageHolder.numChildren - 1 ;
        (pageHolder.getChildAt(w) as MovieClip).gotoAndStop(currentFrame + 1);
//      for (var i:uint = 0; i < pageHolder.numChildren; i++)
//      {
//       trace (+i+'.\t name:' + pageHolder.getChildAt(i).name + '\t type:' + typeof (pageHolder.getChildAt(i)));
//      }
        trace ("down!");
}

function f_prevFrame():void
{
        var w:uint = pageHolder.numChildren - 1 ;
        (pageHolder.getChildAt(w) as MovieClip).gotoAndStop(currentFrame - 1);
//      for (var i:uint = 0; i < pageHolder.numChildren; i++)
//      {
//       trace (+i+'.\t name:' + pageHolder.getChildAt(i).name + '\t type:' + typeof (pageHolder.getChildAt(i)));
//      }
        trace ("up!");
}

编辑:澄清一下代码

Edit2: TL;DR: 问题是最后一段代码的三个函数无法控制 mc page1 的时间线,它是 mc pages 的子节点,它被逐帧推入数组并在运行时加载到精灵页面持有者。如何控制单页movieclip的时间线?

4

1 回答 1

0

终于让它工作了。这将作为一个完美的PowerPoint替代品:D

您需要将单个幻灯片( mc 的每一帧上的一个影片剪辑pages)命名为page0page1,然后可以使用此代码控制它们的时间轴(只需替换上面问题中列出的函数):

function f_nextFrame():void
{
    var temp:uint = pageHolder.numChildren - 1;
    var frame:uint = ((pageHolder.getChildAt(temp) as MovieClip)["page" + targetIDnew].currentFrame);
    (pageHolder.getChildAt(temp) as MovieClip)["page" + targetIDnew].gotoAndStop(frame + 1);
}

function f_prevFrame():void
{
    var temp:uint = pageHolder.numChildren - 1;
    var frame:uint = ((pageHolder.getChildAt(temp) as MovieClip)["page" + targetIDnew].currentFrame);
    (pageHolder.getChildAt(temp) as MovieClip)["page" + targetIDnew].gotoAndStop(frame - 1);
}
于 2013-04-23T14:42:23.430 回答