I have a situation where, upon loading my swf, I add an event listener to the stage to listen for keyboard commands. One of them is to listen for the spacebar, and if it is pressed, it should play a movie. The problem is, that movie is not loaded until later on, depending other user interactions, therefore, until it is loaded, the reference to it would be undefined. But if I wait and add the listener for key commands only when the movie is loaded, then I can't utilize the listener for other keyboard commands, like RIGHT or LEFT, which are the buttons which get you to the movie in the first place. Is there a way to add a conditional or something to prevent that code from being executed if the video is not defined yet? Here's my code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
function togglePause(event:MouseEvent):void {
video.videoPaused = !video.videoPaused; //video is undefined initially so this throws errors.
}
function keyPressedDown(event:KeyboardEvent):void {
switch (key) {
case 32: //Spacebar
//togglePause();
}
}
function loadVideo(){ //called based on user interactions which happen later on
var video:VideoLoader = new VideoLoader(project_array[cp].project_display_files[0], {name:"myVideo", container:this, bgColor:0x000000, autoPlay:false, volume:1,onComplete:vidLoaded});
video.load(); //currently set up for only one video ([0])-->
}