在切换场景时遇到问题,在完全加载时自动加载的flvplayback场景,无法启动

时间:2014-01-28 03:48:45

标签: actionscript-3 flash

这里是我的代码:

stop();
import flash.events.Event;
import fl.video.*;

var files:Array;
var shuffledFiles:Array;

loaderInfo.addEventListener(Event.COMPLETE,ready);

function ready(event:Event):void{
    loaderInfo.removeEventListener(Event.COMPLETE,ready);
    //swf rescale setup
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.addEventListener(Event.RESIZE,stageResized);
    //get FlashVars - a string converted into an Array by spliting it on the , character
    //if the files FlashVar is setup correctly use the data, else use default values
    if(loaderInfo.parameters.files != undefined) files = loaderInfo.parameters.files.indexOf(',') > 0 ? loaderInfo.parameters.files.split(",") : [loaderInfo.parameters.files];
    else files = [ "movie1.flv", "movie2.flv", "movie3.flv" ];
    shuffledFiles = shuffleArray(files);
    //play the 1st video
    videoPlayer.source = shuffledFiles[0];
    shuffledFiles.shift();

    //see when the video finished playing
    videoPlayer.addEventListener(Event.COMPLETE,videoFinished);
}
function videoFinished(event:Event):void{
    if(shuffledFiles.length == 0) shuffledFiles = shuffleArray(files);//all files played, repeat process
    videoPlayer.source = shuffledFiles[0];//play the first video in the random list
    videoPlayer.play();
    trace('playing',shuffledFiles[0]);

    shuffledFiles.shift();//remove the first video from the random list (e.g. [2,0,1].shift() becomes [0,1])
}
function stageResized(event:Event):void{
    videoPlayer.width = stage.stageWidth;
    videoPlayer.height = stage.stageHeight;
}
function shuffleArray(source:Array,clone:Boolean = true):Array {
    var output:Array = [];
    var input:Array = clone ? [].concat(source) : source;//clone ? preserve orignal items by making a copy for shuffling, or not
    while(input.length) output.push(input.splice(int(Math.random() * input.length-1),1)[0]);
    return output;
}

function fl_ClickToGoToScene():void
{
    MovieClip(this.root).gotoAndPlay(2, "Scene 2");
}

function fl_ClickToGoToScene2():void
{
    MovieClip(this.root).gotoAndPlay(1, "Scene 1");
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void{
//trace("Key Pressed: " + String.fromCharCode(e.charCode) + " (character code: " + e.charCode + ")");
checkkeydown(String.fromCharCode(e.charCode));
}

function checkkeydown(keypress:String):void{
    //trace(keypress);
    if(keypress == "z"){
        fl_ClickToGoToScene();
    }
    else if(keypress == "x"){
        fl_ClickToGoToScene2();
    }
}

我尝试制作: 2场面的比赛。 第一个场景,自动播放视频并永远重复播放,(动作脚本) 第二个场景,flash播放短片(时间轴)

问题: 当我运行我的代码时,第一个场景播放得很好, 当我切换场景2时,它也很好玩, 但是当我重新切换到场景1时,flyplayback没有运行。 我可以毫无问题地重新切换到场景2。

我不知道问题出在哪里。我完全是诺布。 ty提前。

  

修改

首先我要把stop();在代码顶部,因为它将在第一部电影结束后播放场景2。 然后我得到了trace的输出('playing',shuffledFiles [0]);

  

播放movie1.flv

     

播放movie3.flv

     

播放movie2.flv

     

播放movie1.flv

     

TypeError:错误#1009:无法访问空对象引用的属性或方法。       在praperkahwinan_fla :: MainTimeline / videoFinished()       在flash.events::EventDispatcher/dispatchEventFunction()       at flash.events::EventDispatcher/dispatchEvent()       在fl.video::FLVPlayback/ http://www.adobe.com/2007/flash/flvplayback/internal::handleVideoEvent()       在flash.events::EventDispatcher/dispatchEventFunction()       at flash.events::EventDispatcher/dispatchEvent()       在fl.video::VideoPlayer/ http://www.adobe.com/2007/flash/flvplayback/internal::httpDoStopAtEnd()       在fl.video::VideoPlayer / http://www.adobe.com/2007/flash/flvplayback/internal::httpNetStatus()

当我在第五个循环上按“z”时发生

错误。

  

此处链接到源文件。

https://www.mediafire.com/?42yk3knhiyxa181 我不包括电影文件。你需要将3个flv电影,movie1.flv,movie2.flv,movie3.flv放在与源文件相同的文件夹中。

1 个答案:

答案 0 :(得分:1)

好的,你的shuffle方法没有正确克隆错误。

试试:

function shuffleArray(source:Array):Array {
    var output:Array = [];
    var input:Array = [].concat(source);
    while(input.length) output.push(input.splice(int(Math.random() * input.length-1),1)[0]);
    return output;
}