-2

I want to loop some video in flash, I found this code but get "Access of possible undefined property COMPLETE through a reference with static type Class" when I try to run it.

video.source="video.flv";
import fl.video.*;
function onFLVCOMPLETE(event:VideoEvent):void{
            event.target.play();
}
video.addEventListener(VideoEvent.COMPLETE, onFLVCOMPLETE);

No clue what is going on so any help would be great

Aaron Owen
  • 33
  • 4
  • @FabriceBacquart wow, you went a bit overboard on your comment? Just because you understand it doesn't mean everyone else does, I've never used flash/ actionscript before and I'm trying to learn. – Aaron Owen May 12 '16 at 12:02
  • @AaronOwen - Did you get it figured out? Ignore the comment above, your `import fl.video.*;` would import the desired class so there's no need to add `import fl.video.VideoEvent` (though the latter is better practice as it's more specific). Some people here like to be critical and downvote without properly understanding what's being asked and what the issue is... – BadFeelingAboutThis May 13 '16 at 17:08
  • @FabriceBacquart - the OP is importing that class: `import fl.video.*` the wildcard `*` imports all classes in that package, which would include fl.video.VideoEvent. The issue is the one in the second part of my answer, it is actually a very good question with a rather obscure solution that is definitely not obvious. – BadFeelingAboutThis May 13 '16 at 17:17
  • Oh yeah, missed that line, for some reason xD – Fabrice Bacquart Jun 06 '16 at 14:42

1 Answers1

2

EDIT

This is what is happening:

The FlashPro/AdobeAnimate IDE automatically imports the flash.events package (whether or not you've explicitly told it to). When it does this, the flash.events.VideoEvent class replaces your imported fl.video.VideoEvent class as what is referenced when you use VideoEvent.

To remedy this, you just need to use the fully qualified class name. So instead of using:

 VideoEvent

You use:

fl.video.VideoEvent

So your code should look like this:

function onFLVCOMPLETE(event:fl.video.VideoEvent):void{
            event.target.play();
}
video.addEventListener(fl.video.VideoEvent.COMPLETE, onFLVCOMPLETE);

To test this behavior, you create a new FlashPro project with following code on the timeline: (you'll also need to add a video component to the library)

import fl.video.VideoEvent;
trace(flash.utils.getQualifiedClassName(VideoEvent));

The expected result in the output window is fl.video::VideoEvent, but the actual result is:

flash.events::VideoEvent

So even though you only imported fl.video.VideoEvent, VideoEvent is referring to flash.events.VideoEvent (which was NOT imported).

BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • 2
    I think that the right `VideoEvent` that OP is looking for is the [`fl.video.VideoEvent`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/video/VideoEvent.html) class which has the [`COMPLETE`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/video/VideoEvent.html#COMPLETE) constant ... – akmozo May 09 '16 at 20:00
  • @Aaron Owen - with consideration to the comment above by @akmozo, perhaps you are getting clashing VideoEvent classes (the one from the `flash.events` package and the one from the `fl.video` package) - try this and see if it fixes it: `video.addEventListener(fl.video.VideoEvent.COMPLETE, onFLVCOMPLETE);` Though, all those complete events are the same string so it should work with `Event.COMPLETE` just as well as `fl.video.VideoEvent.COMPLETE` – BadFeelingAboutThis May 09 '16 at 20:10
  • @akmozo, good catch, I don't use the fl package/components and have never noticed there was another VideoEvent class. – BadFeelingAboutThis May 09 '16 at 20:23