Skip navigation
ThnderBlt
Currently Being Moderated

EventListener not working - AS2

Sep 21, 2012 10:05 AM

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

 
Replies
  • kglad
    72,182 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 21, 2012 11:00 AM   in reply to ThnderBlt

    is your flv playing in an flvplayback component?  if yes, what's the instance name of that component?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 21, 2012 11:27 AM   in reply to ThnderBlt

    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.

     
    |
    Mark as:
  • kglad
    72,182 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 21, 2012 2:24 PM   in reply to kglad

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

     
    |
    Mark as:
  • kglad
    72,182 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 21, 2012 3:20 PM   in reply to ThnderBlt

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

     
    |
    Mark as:
  • kglad
    72,182 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 21, 2012 10:21 PM   in reply to ThnderBlt

    all that code should be on the same frame.  in addition, the timeline should not move from that frame or, if it does, there should be no keyframe in the layer with logoFLV.

     
    |
    Mark as:
  • kglad
    72,182 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 22, 2012 9:49 AM   in reply to ThnderBlt

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

    }

     
    |
    Mark as:
  • kglad
    72,182 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 7:12 AM   in reply to ThnderBlt

    you're welcome.

     

    (sorry, that format for trace is from as3.  replacing the commas by +" "+ will work for as2.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points