Copy link to clipboard
Copied
Hello everybody, I'm new to Adobe Animate / Flash and ActionScript.
I'm working on a simple interactive program for a museum (touch screen kiosk).
I created a menu with a few buttons that, when clicked, load and play MP4 video files that are saved locally and linked to, NOT embeded inside Adobe Animate.
My questions are:
1. How can I do so that when a video ends, the program returns automatically to the main menu.
2. How can I do so that if the user decides to click a menu button the return to the main menu BEFORE the video has finished, the video stops (now I can still hear the audio of the video even if the program has returned to the main menu.
3. How about cache? It is automatically emptied when a video has finished or stopped or do I have to insert some special controls to prevent that become saturate causing problems in the use of the program?
I hope someone can help me. Thanks in advance and forgive my bad English.
Figured it out, two things were wrong.
The video on the stage is named "video_galvani" not "myVideo".
The COMPLETE event is not a VideoEvent, it's just Event.
Here is a working version of that whole frame script:
stop();
stage.addEventListener("gomain", goMainMenu);
function goMainMenu(e: Event) {
gotoAndPlay(10, "Menu_01A");
}
video_galvani.addEventListener(Event.COMPLETE, completePlay);
function completePlay(e: Event): void {
video_galvani.removeEventListener(Event.COMPLETE, completePlay);
//also re
...Copy link to clipboard
Copied
how are you playing your video?
eg, are you using an flvplayback component? are you using the netstream class? are you using a video component? something else?
Copy link to clipboard
Copied
Hi kglad,
@how are you playing your video?
for this early test I imported it as a flvplayback component, but I'm open to suggestions.
Copy link to clipboard
Copied
FLVPlayback is probably the easiest to work with, and can play H.264 MP4 as well as FLV. For quality reasons you would choose H.264.
The documentation includes all of the events and methods to control a video:
FLVPlayback - Adobe ActionScript® 3 (AS3 Flash) API Reference
There are tutorials like this one that give examples on how to know when the video ends:
Copy link to clipboard
Copied
Thank you very much Colin. I will read the whole thing and I'll do some tests.
Best,
Roberto
Copy link to clipboard
Copied
1. you can use the complete event
2. you can use the pause or stop method
3. the same video won't be repeatedly cached taking up more and more space.
Copy link to clipboard
Copied
Thinking about the memory demands of playing videos, I would imagine that video playback is done roughly in the way that QuickTime would have done it. The way that worked was to load into memory as quickly as possible, but to play back the video at the correct rate. That would usually mean there was a significant buffer of video ahead of where you are right now.
Working that way it's quite normal for all of RAM to get filled up, but the data is marked as purgable, so if the memory is needed for something else the buffered video gets cleared out.
Copy link to clipboard
Copied
Ok. Here is how I managed to start a video (an external H264 file) placed in scene B when reaching a certain frame in the timeline:
stop();
myVideo.play();
Here is how I managed to stop the video and return to frame 10 of the main menu (scene A) if the user click on a button:
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPauseVideo);
function fl_ClickToPauseVideo(event:MouseEvent):void
{
myVideo.pause();
}
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_10);
function fl_ClickToGoToScene_10(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(10, "MAIN_MENU");
}
The thing I cannot do is to automatically return to the main menu (scene A) when the video instance "myVideo" as reached the end.
I tried the following but doesn't work:
myVideo.addEventListener(VideoEvent.COMPLETE, completePlay);
function completePlay(e:VideoEvent):void
{
MovieClip(this.root).gotoAndPlay(10, "MAIN_MENU");
}
Copy link to clipboard
Copied
What is this.root? Do you mean the level up from where the code is located? If that's the case it might need to be:
MovieClip(parent).gotoAndPlay(10, "MAIN_MENU");
A different approach you could look into would be sending events. In your top level code you would have something like this:
stage.addEventListener("gomain",goMainMenu);
function goMainMenu(e:Event){
gotoAndPlay(10, "MAIN_MENU");
}
Then in the video player code you would have:
myVideo.addEventListener(VideoEvent.COMPLETE, completePlay);
function completePlay(e:VideoEvent):void
{
myVideo.removeEventListener(VideoEvent.COMPLETE, completePlay);
//also remove any other listeners you set up
stage.dispatchEvent(new Event("gomain"));
}
The advantage of dispatchEvent and listening for it is that it doesn't matter how deep the video code is, the event would get picked up ok.
Copy link to clipboard
Copied
Hi Colin,
the following part of your suggested script works fine, at least when it is associate with the return to main button:
stage.addEventListener("gomain",goMainMenu);
function goMainMenu(e:Event){
gotoAndPlay(10, "MAIN_MENU");
}
But if I add this other part to return to the main menu after the "myVideo" instance has finished, the result is that all of the scripts are ignored:
myVideo.addEventListener(VideoEvent.COMPLETE, completePlay);
function completePlay(e:VideoEvent):void
{
myVideo.removeEventListener(VideoEvent.COMPLETE, completePlay);
//also remove any other listeners you set up
stage.dispatchEvent(new Event("gomain"));
}
Copy link to clipboard
Copied
Here is the Adobe Animate project (less than 1 MB), in case you want to give it a chance:
http://www.baldavision.com/marconi/marconi.zip
Only the first button to the left of each menu is active.
Thank you very much for your help.
Roberto
Copy link to clipboard
Copied
Figured it out, two things were wrong.
The video on the stage is named "video_galvani" not "myVideo".
The COMPLETE event is not a VideoEvent, it's just Event.
Here is a working version of that whole frame script:
stop();
stage.addEventListener("gomain", goMainMenu);
function goMainMenu(e: Event) {
gotoAndPlay(10, "Menu_01A");
}
video_galvani.addEventListener(Event.COMPLETE, completePlay);
function completePlay(e: Event): void {
video_galvani.removeEventListener(Event.COMPLETE, completePlay);
//also remove any other listeners you set up
stage.dispatchEvent(new Event("gomain"));
}
video_galvani.play();
main_1.addEventListener(MouseEvent.CLICK, fl_ClickToPauseVideo);
function fl_ClickToPauseVideo(event: MouseEvent): void {
video_galvani.pause();
}
main_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_10);
function fl_ClickToGoToScene_10(event: MouseEvent): void {
stage.dispatchEvent(new Event("gomain"));
}
Copy link to clipboard
Copied
It works wonderfully!
Thank you very much for you help.
Best,
Roberto
Copy link to clipboard
Copied
Hi Colin,
I added a second video and used the same script you wrote with the new scene, updating the name of the instances. Unfortunately it doesn't work: "Error:1021 Duplicate Function Definition"
I'm not sure what else I have to change in your original script for every new video to avoid that.
I uploaded the updated project here:
http://www.baldavision.com/marconi/marconi2.zip
Thanks for your help.
Roberto
Copy link to clipboard
Copied
In publishing settings there's an option to Allow Debugging. Turning that on would help to find problems quicker.
For the duplicate functions problem, you could create a Document class that has those functions, and then all scenes should be able to get at them. Or rename the duplicates. fl_ClickToPauseVideo1, fl_ClickToPauseVideo2, etc.