Copy link to clipboard
Copied
Hello everyone. I have some questions about video and AS3. I am coding in some video and need it to loop. I am new to this so my set up may be wrong. Feel free to give suggestions on fixes. Right now I have an FLVPlayback component on the first frame of a movie clip. In my main time line I call up the movie clip:
var AL_mc:AL = new AL();
addChild(AL_mc);
There are 2 things I would like to know about this. First, how can I make this loop. I figured I could extend the timeline of the movie clip containing the FLVPlayback to the length of the video, but its a long video and I would rather code it so it is exact. I tried just making the movie clip 2 frames and this sort of worked, but the video got very choppy on the second time around. Second, I need to remove the video on an event. In AS3, how do I completely remove the movie clip until I call it again?
Thanks!
Copy link to clipboard
Copied
So, are you saying that FLVPlayback instance is inside AL class?
If you want to loop a video that is played by FLVPlayback - you, perhaps, need to listener for an events that indicates that video is finished and then call seek and move playhead to 0 - it will play from the beginning.
Copy link to clipboard
Copied
AL is the Linkage class for the movie clip AL_mc. The FLVPlayback component is on the first, and only, frame of AL_mc. What you suggest makes sense, but how would that be done. And would it matter that AL_mc is only one frame?
Copy link to clipboard
Copied
It can be done by setting FLVPlayback instance to desired configuration and listening to events that this instance dispatches during video playback. Here is documentation:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlayback.html
EDIT:
It doesn't matter how many frames you use - video streaming doesn't depend on frames on timeline. You should leave it to one frame.
Copy link to clipboard
Copied
Ok, I seem to have it working. I have a mouse move event setup to kill the video:
addEventListener(MouseEvent.MOUSE_MOVE, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void
{
myVideo.stop();
removeChild(myVideo);
removeEventListener(MouseEvent.MOUSE_MOVE, ALbtnClicked);
}
One thing that is throwing a wrench in the works is that I run it at full screen it seems that the video blocks the mouse move. If I play it windowed, it seems to work fine because the video doesnt cover the whole stage. Thoughts?
I can post more of my code if needed.
Thanks!
Copy link to clipboard
Copied
Why do you need to use MOUSE_MOVE? Why not to use MOUSE_CLICK event?
Copy link to clipboard
Copied
I am using Mouse_Move because it is a touch screen kiosk and the video is a screen saver that needs to be interrupted by a user touching the screen. Would it make a difference for what I need to code?
Copy link to clipboard
Copied
I never developed for touch screen. From what I am reading they say touch screen is practically mouse. Also, I saw some suggestions to use MOUSE_DOWN event in the situations like yours.
Copy link to clipboard
Copied
Yeah, the touchscreen is pretty much a mouse. So I have coded MOUSE_MOVE, MOUSE_DOWN, etc, and they all work to a certain extent. The problem comes in when I run the swf at full screen. Then it seems like the video "covers over" the mouse event. Just to see I attached the event listener to the actual video and that works, but then I am not sure how to remove the video. So the code looks like this..
myVideo.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void
{
myVideo.stop();
removeChild(myVideo);
removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
And that will work, but because the event is now attached to myVideo, it cannot removeChild, because it is no longer the child. So any ideas on how to code that?
Copy link to clipboard
Copied
Since entire screen is a mouse, would it work for you of you add event listener to stage?
stage.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
EDIT:
Of course you will need to make sure that video exists:
function ALbtnClicked(event:MouseEvent):void
{
if(this.contains(myVideo)){
myVideo.stop();
removeChild(myVideo);
}
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
Copy link to clipboard
Copied
In theory this would work. This is the code:
stage.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void
{
if(this.contains(myVideo)){
myVideo.stop();
removeChild(myVideo);
}
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
It is giving me an error when I click:
TypeError: Error #1006: contains is not a function.
at MethodInfo-720()
Copy link to clipboard
Copied
What the scope of [this]?
If it is on timeline, try:
MovieClip(root).contains(myVideo);
Copy link to clipboard
Copied
I am not sure what the scope is. I am not even sure what "this" is.
Copy link to clipboard
Copied
What does it write when you do:
trace(this);
Copy link to clipboard
Copied
[object MainTimeline]
Copy link to clipboard
Copied
Again, try
MovieClip(root).contains(myVideo);
or
DisplayObject(this).contains(myVideo);
or
DisplayObjectContainer(root).contains(myVideo);
Copy link to clipboard
Copied
Forgive my ignorance, but where in the code would those go?
Thanks!
Copy link to clipboard
Copied
Into ALbtnClicked function - you should check if video is on display list before you remove it.
Copy link to clipboard
Copied
I am still getting errors. For example:
stage.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void
{
MovieClip(root).contains(myVideo);
myVideo.stop();
removeChild(myVideo);
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
Gives me this:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-720()
Copy link to clipboard
Copied
Look, we already discussed that.
You have to check if myVideo is on display list before your remove it - if statement with checking by using contains() accomplishes that.
Copy link to clipboard
Copied
Sorry. I guess I am just getting a little confused about where to put those things you mentioned before. Is this what you meant?:
stage.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void
{
MovieClip(root).contains(myVideo);
if(this.contains(myVideo)){
myVideo.stop();
removeChild(myVideo);
}
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
This still gives me the error about contains not being a functions. I am still very new to this so I apologize if I am not getting what you are saying, and I do really appreciate the help.
Copy link to clipboard
Copied
Try:
if(MovieClip(root).contains(myVideo)){
Copy link to clipboard
Copied
stage.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void
{
MovieClip(root).contains(myVideo);
if(MovieClip(root).contains(myVideo)){
myVideo.stop();
removeChild(myVideo);
}
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
This does not give any errors, but it is not functioning now, even when not in full screen mode.
Copy link to clipboard
Copied
You don't need the following line:
MovieClip(root).contains(myVideo);
The function should be:
function ALbtnClicked(event:MouseEvent):void{
if(MovieClip(root).contains(myVideo)){
myVideo.stop();
removeChild(myVideo);
}
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
Copy link to clipboard
Copied
Ok. Still no errors, but still no functionality. Here is some more of the code that may help shed light:
import fl.video.*;
var myVideo:FLVPlayback = new FLVPlayback();
myVideo.source = "mTOR Attract Loop_ESMO_0.1.f4v";
addChild(myVideo);
myVideo.y = 0;
myVideo.x = 0;
myVideo.width = 1080;
myVideo.height = 1920;
mm_clear();
stage.addEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
function ALbtnClicked(event:MouseEvent):void{
if(MovieClip(root).contains(myVideo)){
myVideo.stop();
removeChild(myVideo);
}
stage.removeEventListener(MouseEvent.MOUSE_DOWN, ALbtnClicked);
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more