I have been tearing my hair out on this one.
I found some code on a FAQ site that seems like it should work, but I can't get it to function. I have put an .flv video into my scene, it plays fine, but then I need the program to move to the next scene.
Here is the code:
onClipEvent (enterFrame) {
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
stopAllSounds();
trace ("Event Fired");
_root.gotoAndPlay("First Time User",1);
}
this.addEventListener("complete",listenerObject);
}
I added in the trace to see if the function was firing at all, and I actually get the message in my output 12 times!
I'd really appreciate any help with this.
TIA,
Jason
onClipEvent(enterFrame) { ... } is going to run that code every single frame. So you're setting up a listener over and over and over again, which explains the duplication. First thing is to remove that onClipEvent(enterFrame){} and just use the code inside it.
You're applying the listener to "this" so whatever clip you pasted that code on the timeline inside has to fire off a complete event. Chances are (as kglads pointing out) what you're applying that listener to isn't the video.
Yes, the instance name is logoFLV.
The scene where all this is taking place has only 1 frame in the timeline. There are 5 layers.
I tried commenting out the onClipEvent and got a bunch of 'Statement must appear within on/onClipEvent handler'
The code is in the Actions section for the instance.
remove your code. click on an empty part of the stage or back stage to deselect all objects. in the actions panel, in the first keyframe that contains logoFLV, paste:
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
stopAllSounds();
trace ("Event Fired");
// _root.gotoAndPlay("First Time User",1);
_root.gotoAndPlay("First Time User"); // don't use scenes in navigation with as2. use frame labels only.
}
logoFLV.addEventListener("complete",listenerObject);
I got the first one working with a pretty ugly redirect, but I have a second scene where the technique is not working.
Workaround:
onClipEvent (enterFrame) {
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
stopAllSounds();
_root.gotoAndPlay(2);
}
this.addEventListener("complete",listenerObject);
}
Code in frame 2 then points to the next scene, and it works.
Trying to use this in a later scene actually pushes me all the way back to the "First Time User" scene. I assume that this is because _root refers to the first scene only. Is there any way to reference any scene in the program (perhaps in reference to the _root)?
@kglad:
I tried the technique you posted (and about half a dozen variants) and did not get any navigation to happeen at the end of the video. It actually doesn't even fire the event for some reason.
The program has been constructed over the last 3 months using over 90 scenes, so getting rid of the scenes at this point is not feasible.
what do the following traces show:
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
stopAllSounds();
trace ("Event Fired");
// _root.gotoAndPlay("First Time User",1);
_root.gotoAndPlay("First Time User"); // don't use scenes in navigation with as2. use frame labels only.
}
logoFLV.addEventListener("complete",listenerObject);
trace(logoFLV);
Yeah, everything is together. The main timeline has 2 frames right now. Frame 1 has all of the content. Frame 2 is just a redirect to the next scene.
I have tried redirecting to the next scene, redirecting to Frame 2, and setting frame labels for either option. Either the traces throw 'undefined' or I just get '_level0.mainFLV'. I do not get the 'Event Fired' trace at all.
If I put the code in a clip event inside the instance, the only way I get any movement is if I repeat the code from the first video. However, the navigation seemingly directs me to Frame 2 of the first scene instead of the current scene (9th).
onClipEvent (enterFrame) {
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
stopAllSounds();
_root.gotoAndPlay(2);
}
this.addEventListener("complete",listenerObject);
}
I do have a button in the scene which can be used to navigate forward. Is there a way to activate the on (release) method of the button at the end of the video instead?
again, delete the code you are using. there are so many problems with that code, it is not salvageable.
click on logoFLV and cut the contentPath string from the properties panel.
attached to the frame that contains logoFLV, what trace output do you see when you copy and paste the following code. change nothing except to assign the path/name for your flv and allow to run until your video ends.
stop();
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void {
stopAllSounds();
trace ("Event Fired");
clearInterval(traceI);
// _root.gotoAndPlay("First Time User",1);
_root.gotoAndPlay("First Time User"); // don't use scenes in navigation with as2. use frame labels only.
}
logoFLV.addEventListener("complete",listenerObject);
logoFLV.contentPath = "path/filename.flv"; // paste the contentPath string you cut from the properties panel.
var tl:MovieClip=this;
trace(logoFLV,this,this._currentframe);
clearInterval(traceI);
traceI=setInterval(traceF,3000);
function traceF():Void{
trace(tl._currentframe);
}
Alright, that works perfectly! Is it just by putting in the contentpath in the code instead of when you add the file that makes the difference? I don't get it, but it is awesome that it is working.
Flash didn't like the multi-parameter trace statement 'trace(logoFLV,this,this._currentframe);' so I commented out to test and I got 1 several times and then 'Event Fired'. I used it on the second video, and I got 391 a bunch of times because that video was much longer and the event fired as well.
The last thing I have to do is play videos dynamically after a button click. Will this technique work for that as well? Actually, I figured this out. I am all set!
Thanks so much,
Jason
North America
Europe, Middle East and Africa
Asia Pacific