【问题标题】:having trouble when switching scene, scene with flvplayback that load automatic on complete loading, cant start切换场景时遇到问题,带有 flvplayback 的场景在完成加载时自动加载,无法启动
【发布时间】:2014-02-19 05:04:32
【问题描述】:

这是我的代码:

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。

我不知道问题出在哪里。我完全是菜鸟。提前联系。

编辑

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

的输出

播放movie1.flv

播放movie3.flv

播放movie2.flv

播放movie1.flv

TypeError:错误 #1009:无法访问空对象引用的属性或方法。 在 praperkahwinan_fla::MainTimeline/videoFinished() 在 flash.events::EventDispatcher/dispatchEventFunction() 在 flash.events::EventDispatcher/dispatchEvent() 在 fl.video::FLVPlayback/http://www.adobe.com/2007/flash/flvplayback/internal::handleVideoEvent() 在 flash.events::EventDispatcher/dispatchEventFunction() 在 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 放在与源文件相同的文件夹中。

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案1】:

    好的,您的随机播放方法出现错误,无法正确克隆。

    试试看:

    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;
    }
    

    【讨论】:

    • 首先 i hv 添加 stop();在代码的顶部,因为没有它它会进入场景 2。输出正在播放movie1.flv 正在播放movie3.flv 正在播放movie2.flv 正在播放movie1.flv
    • 我可以给你我的源文件吗?我对“x”按有问题。它确实回到了场景 2,但它是空白的..
    • 检查最新的编辑,如果有剩余,复制粘贴错误堆栈
    • 没有错误,但是按z后按x返回场景1,flyplayback没有运行。
    • trace('playing',shuffledFiles[0]);回归?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多