Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Video coding...

Community Beginner ,
Sep 09, 2009 Sep 09, 2009

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!

TOPICS
ActionScript
5.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2009 Sep 09, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 10, 2009 Sep 10, 2009

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2009 Sep 10, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 11, 2009 Sep 11, 2009

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2009 Sep 11, 2009

Why do you need to use MOUSE_MOVE? Why not to use MOUSE_CLICK event?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 12, 2009 Sep 12, 2009

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2009 Sep 12, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

What the scope of [this]?

If it is on timeline, try:

MovieClip(root).contains(myVideo);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

I am not sure what the scope is. I am not even sure what "this" is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

What does it write when you do:

trace(this);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

[object MainTimeline]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

Again, try

MovieClip(root).contains(myVideo);

or

DisplayObject(this).contains(myVideo);

or

DisplayObjectContainer(root).contains(myVideo);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

Forgive my ignorance, but where in the code would those go?

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

Into ALbtnClicked function - you should check if video is on display list before you remove it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

Try:

if(MovieClip(root).contains(myVideo)){

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 13, 2009 Sep 13, 2009

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 13, 2009 Sep 13, 2009

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines