Skip to main content
QADesign
Known Participant
August 11, 2010
Answered

Reset Flash After Video

  • August 11, 2010
  • 1 reply
  • 1712 views

Hello:

I have animation in Scene1 and I have button that launches the user to a video in Scene 2. In Scene2 I have the following actionscript to play the video:

var nc:NetConnection = new NetConnection();

nc.connect (null);


var ns:NetStream = new NetStream(nc);


theVideo.attachVideo (ns);


ns.play("homepage.f4v");

The video plays fine, but how do I get the Flash to reset back to Scene1, Frame 1 when it's finished?

Any thoughts?

Thanks!

-Q

This topic has been closed for replies.
Correct answer kglad

use a loop to repeatedly check ns.time.  when ns.time is equal to your f4v's duration (you can use the onMetaData function to find the duration), use a goto method to return to frame 1.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 11, 2010

use a loop to repeatedly check ns.time.  when ns.time is equal to your f4v's duration (you can use the onMetaData function to find the duration), use a goto method to return to frame 1.

QADesign
QADesignAuthor
Known Participant
August 12, 2010

Okay, so that fixed the issue I was having, but then I added some controls to my video player, and now I'm back to square one. Here's my actionscript:

// video connection - and loop back to beginning - Boom

var duration:Number = 0;

var nc:NetConnection = new NetConnection();

nc.connect(null);

var ns:NetStream = new NetStream(nc);

theVideo.attachVideo(ns);

ns.play("homepage.flv");


ns.onMetaData = function(evt:Object):Void {

  duration = evt.duration;

};

ns.onStatus = function(evt:Object):Void {

  if (this.time > 0 && this.time >= duration) {

    trace("Video complete")

gotoAndPlay("Scene 1", 1);


    delete this.onStatus;

  }

}

// Controls

rewindButton.onRelease = function()  {

ns.seek(0);

}


playButton.onRelease = function()  {

ns.pause();

}

//loadbar + scrub

var videoInterval = setInterval(videoStatus,100);

var amountLoaded:Number;


var duration:Number;


ns["onMetaData"] = function(obj) {

duration = obj.duration;

}


function videoStatus() {

amountLoaded = ns.bytesLoaded / ns.bytesTotal;

loader.loadbar._width = amountLoaded * 333.95;

loader.scrub._x = ns.time / duration * 332;


}


var scrubInterval;


loader.scrub.onPress = function() {

clearInterval(videoInterval);

scrubInterval = setInterval(scrubit,10);

this.startDrag(false,2,this._y,331,this._y);

}


loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {

clearInterval(scrubInterval);

videoInterval = setInterval(videoStatus,100);

this.stopDrag();

}


function scrubit() {

ns.seek(Math.floor((loader.scrub._x/331)*duration));

}

Any thoughts? Thanks!!!!!

kglad
Community Expert
Community Expert
August 12, 2010

what's the problem?  is your onStatus method failing to trigger with some event that you need to detect?