Trying to add an event listener for PLAYING/PAUSED_STATE_ENTERED, returning error 1119

94 Views Asked by At

Basically I have a very simple video gallery set up. I want it so that when the video is paused some buttons will become visible on the screen and when it is playing these buttons will not be visible. This is my code:

import fl.video.*;
import fl.video.VideoEvent;
import flash.events.Event;

videoOne.addEventListener(Event.PLAYING_STATE_ENTERED, hideInfo());
videoOne.addEventListener(Event.PAUSED_STATE_ENTERED, showInfo());

function showInfo() {
    thumbnailOne.visible = true;
    thumbnailTwo.visible = true;
    thumbnailThree.visible = true;
    videoGalleryInfo.visible = true;
    infoHidden = 0;
}

function hideInfo() {
    thumbnailOne.visible = false;
    thumbnailTwo.visible = false;
    thumbnailThree.visible = false;
    videoGalleryInfo.visible = false;
    infoHidden = 1;
}

I have tried using Event instead of VideoEvent and so on as this fixed an issue with adding another event listener earlier on for the COMPLETE event, but I'm always returned with

Video gallery, Layer 'ActionScript', Frame 77, Line 22  1119: Access of possibly undefined property PLAYING_STATE_ENTERED through a reference with static type Class.

Video gallery, Layer 'ActionScript', Frame 77, Line 23  1119: Access of possibly undefined property PAUSED_STATE_ENTERED through a reference with static type Class.

I do not understand what I'm doing wrong. Shouldn't the properties be defined through importing fl.video.*; and flash.events.Event;?

EDIT: In case it matters, here is the rest of my code for this particular scene, including the fixes that null suggested. I still get the same errors, plus a "1136: Incorrect number of arguments. Expected 1" error

import flash.events.MouseEvent;
import fl.video.*;
import fl.video.VideoEvent;
import flash.events.Event;

stop();

homeButton.addEventListener(MouseEvent.CLICK, homePressed);
soundButton.addEventListener(MouseEvent.CLICK, soundPressed);
helpButton.addEventListener(MouseEvent.CLICK, helpPressed);
exitButton.addEventListener(MouseEvent.CLICK, exitPressed);

var videoPlaying:int = 0;
var infoHidden:int = 0;

videoOne.addEventListener(Event.COMPLETE, vid1Comp);
function vid1Comp(event:Event) {
    videoOne.visible = false;
    showInfo();
}



videoOne.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
videoOne.addEventListener(VideoEvent.PAUSED_STATE_ENTERED, showInfo);

function showInfo(e:Event):void {
    thumbnailOne.visible = true;
    thumbnailTwo.visible = true;
    thumbnailThree.visible = true;
    videoGalleryInfo.visible = true;
    infoHidden = 0;
}

function hideInfo(e:Event):void {
    thumbnailOne.visible = false;
    thumbnailTwo.visible = false;
    thumbnailThree.visible = false;
    videoGalleryInfo.visible = false;
    infoHidden = 1;
}

thumbnailOne.addEventListener(MouseEvent.CLICK, playVid1);
function playVid1(event:MouseEvent) {
    hideInfo();

    if (musicPlaying == 1) {
        SoundMixer.stopAll();
        musicPlaying = 0;
    }

    videoOne.visible = true;
    videoOne.play();
    videoPlaying = 1;
}

videoOne.visible = false;
2

There are 2 best solutions below

0
On BEST ANSWER

I found that to fix this issue you have to use the full path for the event, so changing

videoOne.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
videoOne.addEventListener(VideoEvent.PAUSED_STATE_ENTERED, showInfo);

to

videoOne.addEventListener(fl.video.VideoEvent.PLAYING_STATE_ENTERED, hideInfo);
videoOne.addEventListener(fl.video.VideoEvent.PAUSED_STATE_ENTERED, showInfo);

fixed it. Pretty simple, really. Thank you for your help regardless, @null.

3
On

This line calls the function hideInfo:

videoOne.addEventListener(Event.PLAYING_STATE_ENTERED, hideInfo());

but it should instead pass the function (and not call it) like so:

videoOne.addEventListener(Event.PLAYING_STATE_ENTERED, hideInfo);

The constants for the type of event that you are adding are defined in the VideoEvent class, so the actual code should look like this:

videoOne.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hideInfo);

The signature of the function should be that of a callback. It should take a single parameter of type Event or appropriate subclass thereof:

function hideInfo(e:Event):void {

You could also do

function hideInfo(e:VideEvent):void {

But you have no use for the parameter anyway, so there's' no real point in specializing the type further unnecessarily.


I still get the same errors, plus a "1136: Incorrect number of arguments. Expected 1" error

That's because you changed the signature of the function as I suggested. As you call your functions without any arguments:

showInfo();

This causes the error that you receive.

In order to avoid that and because you are not making any use of the parameter in those functions you can change the function once again to accept a default value of null for the parameter:

function showInfo(e:Event = null):void {

This way if called without a parameter the parameter defaults to null, which is ok, because you don't need the parameter anyway.