0 Replies Latest reply on Jan 14, 2011 9:19 PM by jordana309-36

    Catching Custom Events in Actionscript


      I have a component that contains a VideoDisplay object. I need my main application to know when it's reached the end of it's playing. I also pass a mess of things into this from my primary window, so there's a lot of bindable variables. So, I currently have the following code in my object:



      <?xml version="1.0" encoding="utf-8"?>
      <!-- This is a window component which creates a transparent window with no system chrome (no bars, close, min, max buttons, resize stuff) that contains a single video object to be able to play videos from a folder called "videos" in the root of this application. This screen is spawned from the main MXML WindowedApplication using AS 3. -->
      <s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
                          systemChrome="none" visible="true" transparent="true" showStatusBar="false" width="400" height="300"
              [Event(name="MOVIE_LOAD", type="flash.events.Event")]
              [Event(name="MOVIE_FINISH", type="flash.events.Event")]
              <!-- Place non-visual elements (e.g., services, value objects) here -->
              <s:BasicLayout />
                  import org.osmf.events.TimeEvent;
                  public var displayScreenWidth:int = 1024;
                  public var displayScreenHeight:int = 768;
                  public var videoName:String;
                  // Note that the following two variables are set to true by default because the screen saver goes in first.
                  public var muteVideo:Boolean=true;
                  public var loopVideo:Boolean=true;
                  protected function dispatchMovieLoad(event:Event):void
                      var eventObj:Event = new Event("MOVIE_LOAD");
                  protected function dispatchMovieFinish(event:TimeEvent):void
                      var eventObj:Event = new Event("MOVIE_FINISH");


          <s:VideoDisplay id="videoDisplayComp" x="0" y="0" width="{displayScreenWidth}" height="{displayScreenHeight}" source="videos/{videoName}"
                                          autoPlay="true" muted="{muteVideo}" loop="{loopVideo}" complete="dispatchMovieFinish(event)" />



      Anyway, when I try to catch the event the event in my main screen's actionscript, I have the following:



      /* Plays a video, and enables sound and disables looping. It also defines what do to when the video reaches completion. */
      protected function playVideo(vidName:String):void
          videoScreen.addEventListener(Event.moviefinish, loadScreenSaver);
          videoScreen.muteVideo = false;
          videoScreen.loopVideo = false;
          videoScreen.videoName = vidName;



      Now, two things to note. I had to go and access the play() method of the videoDisplay. If I can make this a public function, that'd be awesome.