0
votes

here my code:

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

i try to make : 2 scene of play. first scene, flash that automatic play video and repeat it forever, (actionscript) second scene, flash play a short montage (timeline )

problem : when i run my code, first scene play well, when i switch scene 2, it play well too, but when i re-switch to scene 1, flyplayback not running. i can re-switch to scene 2 with no problem.

i dont know where the problem is. im totally noob. ty in advance.

edit

first i hv to put stop(); at top of code, because it will play scene 2 instead after first movie finish. then i got output of trace('playing',shuffledFiles[0]);

playing movie1.flv

playing movie3.flv

playing movie2.flv

playing movie1.flv

TypeError: Error #1009: Cannot access a property or method of a null object reference. at praperkahwinan_fla::MainTimeline/videoFinished() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at fl.video::FLVPlayback/http://www.adobe.com/2007/flash/flvplayback/internal::handleVideoEvent() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at fl.video::VideoPlayer/http://www.adobe.com/2007/flash/flvplayback/internal::httpDoStopAtEnd() at fl.video::VideoPlayer/http://www.adobe.com/2007/flash/flvplayback/internal::httpNetStatus()

error occur when i press "z" on fifth loop.

here link to the source file.

https://www.mediafire.com/?42yk3knhiyxa181 im not include movie file. u need to put 3 flv movie, movie1.flv, movie2.flv , movie3.flv at same folder as source file.

1

1 Answers

1
votes

Ok there was an error in you shuffle method not cloning properly.

Try that:

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