2 Replies Latest reply on Jan 18, 2011 3:13 PM by jordana309-36

    Catching Custom Events in Actionscript


      I have a custom component that opens a new window with a video player in it. I need to pass a bunch of stuff into it, so there's a lot of binding expressions. I need to be able to catch it's complete event (when the video is finished playing). But the event I dispatch isn't working. Here's my custom component class:



      <?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;
                  // In order to allow it to play, I had to extend the play method for the VideoDisplay to a public function.
                  public function play():void
                  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="videoDisplay" x="0" y="0" width="{displayScreenWidth}" height="{displayScreenHeight}" source="videos/{videoName}"
                                          autoPlay="true" muted="{muteVideo}" loop="{loopVideo}" complete="dispatchMovieFinish(event)" />



      When I try to catch the event, I use this code:


      /* 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.MOVIE_FINISH, loadScreenSaver);
          videoScreen.muteVideo = false;
          videoScreen.loopVideo = false;
          videoScreen.videoName = vidName;



      The problem is, i get the error by the addEventListener line that reads:

      Multiple markers at this line:
      -1119: Access of possibly undefined property MOVIE_FINISH through a reference with static type Class.


      I don't know how to get around this. When I type "addEventListener(" and hit control+space bar, I see "Event.MOVIE_FINISH" on the list, citing my custom component as the source. Even when I had it called movieFinish in the component, I still saw "MOVIE_FINISH" for my event in the code help. So, I changed the name, but I cannot get rid of the error, and therefore my program won't compile fully. Any ideas?