Working with custom events
I am trying to work with the EventDispatcher class to dispatch a custom event to stop a video from playing. The video plays inside a MovieClip with an attached class file called PlayerProfile. I want the video in the PlayerProfile MovieClip to stop playing when the user clicks on another MovieClip called ScrollBox. I'm getting no compile or runtime erros, but the code is not stopping the video. I have seen use of a public static constant to represent the custom event. Is that what I am missing here.
Any help, as always, is much appreciated.
Here is the code for the PlayerProfile MovieClip with relevant code in bold:
package
{
import flash.display.MovieClip;
import gs.TweenLite;
import flash.events.MouseEvent;
import flash.events.Event;
public class PlayerProfile extends MovieClip
{
public function PlayerProfile()
{
this.ProfileButton_mc.buttonMode = true;
this.StatisticsButton_mc.buttonMode = true;
this.HomeButton_mc.buttonMode = true;
this.VideoButton_mc.buttonMode = true;
this.ProfileButton_mc.addEventListener(MouseEvent.CLICK, profileClickHandler);
this.StatisticsButton_mc.addEventListener(MouseEvent.CLICK, statisticsClickHandler);
this.HomeButton_mc.addEventListener(MouseEvent.CLICK, homeClickHandler);
this.VideoButton_mc.addEventListener(MouseEvent.CLICK, videoClickHandler);
TweenLite.from(this, .5, {alpha:0});
//adds the listener to receive the stopVideo custom event
this.addEventListener("stopVideo", stopVideoHandler);
}
//method to stop the video
private function stopVideoHandler(event:Event):void
{
this.Video_mc.stop();
}
private function profileClickHandler(event:MouseEvent):void
{
this.Video_mc.stop();
this.gotoAndStop("Profile");
TweenLite.from(event.target, .5, {alpha:0});
}
private function statisticsClickHandler(event:MouseEvent):void
{
this.Video_mc.stop();
this.gotoAndStop("Stats");
TweenLite.from(event.target, .5, {alpha:0});
}
private function homeClickHandler(event:MouseEvent):void
{
this.Video_mc.stop();
event.target.root.gotoAndStop("Home");
}
private function videoClickHandler(event:MouseEvent):void
{
this.gotoAndStop("Video");
TweenLite.from(event.target, .5, {alpha:0});
}
}
}
Here is the code on my Main Timeline that dispatches the event, again with relevant code in bold:
stop();
//adds listeners to call the profile functions
this.ScrollBox.addEventListener(MouseEvent.CLICK, clickHandler);
//functions to advance the movie to the profiles
function clickHandler(event:MouseEvent):void
{
gotoAndStop(event.target.name);
}
//code to dispatch the custom event
this.ScrollBox.addEventListener(MouseEvent.CLICK, stopVideoHandler);
function stopVideoHandler(event:Event):void
{
dispatchEvent(new Event("stopVideo"));
}