Copy link to clipboard
Copied
I have 2 codes on 2 different keyframes i have just copy/pasted. I have changed all the name of functions and variables, I just need one function I don't know how to change name of.
code on key frame 1:
var timedelay2:Number = 10; // seconds delay in replay
var video2;
var nc2:NetConnection;
var ns2:NetStream;
nc2 = new NetConnection();
nc2.connect(null);
ns2 = new NetStream(nc2);
ns2.client = this;
ns2.addEventListener(NetStatusEvent.NET_STATUS,netStatusf2);
function netStatusf2(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF,timedelay*1000);
}
}
function replayF2(){
ns2.play("film/film1.f4v");
}
var durationNum2:Number;
function onMetaData(iObj:Object):void {
durationNum2 = iObj.duration;
}
video2 = new Video(287,263);
video2.x = 231.1;
video2.y = 140.5;
addChild(video2);
video2.attachNetStream(ns2);
ns2.play("film/film1.f4v");
code on key frame 2:
var moviesA:Array =["film/film1.f4v", "film/film2.f4v"];
var movie:String = moviesA[Math.floor(Math.random()*moviesA.length)];
var timedelay:Number = 5; // seconds delay in replay
var video;
var nc:NetConnection;
var ns:NetStream;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusf);
function netStatusf(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF,timedelay*1000);
}
}
function replayF(){
ns.play(movie);
}
var durationNum:Number;
function onMetaData(iObj:Object):void {
durationNum = iObj.duration;
}
video = new Video(287,263);
video.x = 231.1;
video.y = 140.5;
addChild(video);
video.attachNetStream(ns);
ns.play(movie);
problem is this function, I don't really know how to give one of the function another name so they don't interfere with each other...?
function onMetaData(iObj:Object):void {
durationNum2 = iObj.duration;
anyone that can help..?
1 Correct answer
1. you're not closing ns when you remove video. so, ns will continue to play even though it's not visible. if it's already completed play it will restart after that delay. to remedy, use: ns.close() when a button is clicked.
2. you're not attaching ns2 to video2. you're attaching ns. to remedy, use: video2.attachNetStream(ns2);
3. you're not using timedelay2. use it.
Copy link to clipboard
Copied
you don't need two different onMetaData functions. but if you wanted to, create a movieclip (say mc), and use
ns.client=mc;
mc.onMetaData=function(iObj:Object){
//
}
Copy link to clipboard
Copied
if I don't change the names it gives me an error saying: "1021: Duplicate function definition."
and do I put the following code:
var timedelay2:Number = 10;
var video2;
var nc2:NetConnection;
var ns2:NetStream;
nc2 = new NetConnection();
nc2.connect(null);
ns2 = new NetStream(nc2);
ns2.client = mc;
ns2.addEventListener(NetStatusEvent.NET_STATUS,netStatusf2);
function netStatusf2(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF,timedelay*1000);
}
}
function replayF2(){
ns2.play("film/film1.f4v");
}
var durationNum2:Number;
mc.onMetaData = function(iObj:Object):void {
durationNum2 = iObj.duration;
}
video2 = new Video(287,263);
video2.x = 231.1;
video2.y = 140.5;
addChild(video2);
video2.attachNetStream(ns2);
ns2.play("film/film1.f4v");
Copy link to clipboard
Copied
you can use one onMetaData() function to return info about both netstreams.
or:
kimtrager wrote:
I have 2 codes on 2 different keyframes i have just copy/pasted. I have changed all the name of functions and variables, I just need one function I don't know how to change name of.
code on key frame 1:
var timedelay2:Number = 10; // seconds delay in replay
var video2;
var nc2:NetConnection;
var ns2:NetStream;
nc2 = new NetConnection();
nc2.connect(null);
ns2 = new NetStream(nc2);
ns2.client = this;
ns2.addEventListener(NetStatusEvent.NET_STATUS,netStatusf2);
function netStatusf2(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF,timedelay*1000);
}
}
function replayF2(){
ns2.play("film/film1.f4v");
}
var durationNum2:Number;
function onMetaData(iObj:Object):void {
durationNum2 = iObj.duration;
}
video2 = new Video(287,263);
video2.x = 231.1;
video2.y = 140.5;
addChild(video2);
video2.attachNetStream(ns2);
ns2.play("film/film1.f4v");
code on key frame 2:
var mc:MovieClip=new MovieClip;
var moviesA:Array =["film/film1.f4v", "film/film2.f4v"];
var movie:String = moviesA[Math.floor(Math.random()*moviesA.length)];
var timedelay:Number = 5; // seconds delay in replay
var video;
var nc:NetConnection;
var ns:NetStream;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = mc;
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusf);
function netStatusf(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF,timedelay*1000);
}
}
function replayF(){
ns.play(movie);
}
var durationNum:Number;
function onMetaData(iObj:Object):void {
durationNum = iObj.duration;
}
video = new Video(287,263);
video.x = 231.1;
video.y = 140.5;
addChild(video);
video.attachNetStream(ns);
ns.play(movie);
mc.onMetaData = function(iObj:Object):void {
durationNum2 = iObj.duration;
}
Copy link to clipboard
Copied
hey again
i'm now just using
var durationNum:Number;
function onMetaData(iObj:Object):void {
durationNum = iObj.duration;
}
on frame 1. But it seems i've lost the randomness on frame 2. it only plays "film/film1.f4v" all the time even though i put multiply times "film/film2.f4v". Is this true, or is it just me who have been very unlucky..?
my frame 1 looks like this at the moment:
var timedelay:Number = 10;
var video;
var nc:NetConnection;
var ns:NetStream;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusf);
function netStatusf(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF,timedelay*1000);
}
}
function replayF(){
ns.play("film/film1.f4v");
}
var durationNum:Number;
function onMetaData(iObj:Object):void {
durationNum = iObj.duration;
}
video = new Video(287,263);
video.x = 231.1;
video.y = 140.5;
addChild(video);
video.attachNetStream(ns);
ns.play("film/film1.f4v");
stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void{
if (event.target.name!=null){
switch(event.target.name) {
case "work1_btn":
gotoAndStop("work1");
removeChild(video);
break;
case "contact_btn":
gotoAndStop("contact");
removeChild(video);
break;
case "frontpage2_btn":
gotoAndStop("frontpage2");
removeChild(video);
break;
}
}
}
And my frame 2 looks like this:
var moviesA2:Array =["film/film1.f4v", "film/film2.f4v", "film/film2.f4v", "film/film2.f4v", "film/film2.f4v"];
var movie2:String = moviesA2[Math.floor(Math.random()*moviesA2.length)];
var timedelay2:Number = 0; // seconds delay in replay
var video2;
var nc2:NetConnection;
var ns2:NetStream;
nc2 = new NetConnection();
nc2.connect(null);
ns2 = new NetStream(nc2);
ns2.client = this;
ns2.addEventListener(NetStatusEvent.NET_STATUS,netStatusf2);
function netStatusf2(e:NetStatusEvent) {
if (e.info.code == "NetStream.Play.Stop" && Math.abs(durationNum-ns.time)<.1) {
setTimeout(replayF2,timedelay*1000);
}
}
function replayF2(){
ns2.play(movie2);
}
video2 = new Video(287,263);
video2.x = 231.1;
video2.y = 140.5;
addChild(video2);
video2.attachNetStream(ns);
ns2.play(movie2);
stage.addEventListener(MouseEvent.CLICK, clickHandler2);
function clickHandler2(event:MouseEvent):void{
if (event.target.name!=null){
switch(event.target.name) {
case "frontpage2_btn2":
gotoAndStop("frontpage2");
removeChild(video2);
}
}
}
Copy link to clipboard
Copied
1. you're not closing ns when you remove video. so, ns will continue to play even though it's not visible. if it's already completed play it will restart after that delay. to remedy, use: ns.close() when a button is clicked.
2. you're not attaching ns2 to video2. you're attaching ns. to remedy, use: video2.attachNetStream(ns2);
3. you're not using timedelay2. use it.
Copy link to clipboard
Copied
Sooooo damn great:)
thank you so much - it works perfectly...
Copy link to clipboard
Copied
you're welcome.

