playing 3 flv in one flashfile

  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Hello Flash experts,

Im in a situation where I have 3 flv's and I would like to merge them into 1 flashfile. This could be easy but I also want to make 3 buttons in the merged flash file, where each button plays one of the 3 flv's

So to reduce loadingtime, I would like to load the 3 files via a flahfile, and not as one completly merged file.

At the same time, when clicking on button one, all 3 flv should play in a row, if clicked on button 2, only flv2 and flv3 should play etc.
Image
I am only a beginner in flash, and action scripting. My thought was to use the loadmovie() command but I cant get it to work.

Have some of you any idea to how to solve this problem, and eventualy guide me in the right direction.

Thanks.

/Martin
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

The problem with FLVs is they have to be on Frame 1 of the movie timeline.

To play them consecutively this worked for me.
First of all we'll be working with Action Script 2 and the FLVPlayback component, so you have to be using Flash 8 or higher.

For a test example create a flash file for each of your FLVs

Call the first one flv1.swf the second flv2.swf and the third flv3.swf and add your flvplayback component and appropriate flv to each on frame one of layer one
*note* - save all files to the same root directory of the folder you are working in.
*important to note* In order for what I'm going to show you to work, when encoding your FLVs you need to add two cuepoints. At the very beginning of the movie add a cuepoint and call it "begin" with a type of "navigation". Then scrub to the end of the movie and give it a cuepoint and give it a name of "end" with a type of "event" (navigation would also probably work but I usually use event - I've gotten into the habit of doing this with all my FLV's when I encode them so that at the very least I have a beginning and ending cuepoint. - if your flv's don't have cuepoints encoded, you can "create" them with action script and event listeners, but it's a good bit more complicated.)

Then create a new movie and call it main.swf and give a name of your choice to layer 1
and then add a new layer and call it labels, and then add an actions layer.

On all layers add a keyframe at frame 10 and one at frame 20 and one at frame 30 (you could do it on just frame 2 and 3 but you're going to want to label frame 1,10 and 20 and putting your keyframes there will let you be able to see/read your labels.


Let's start with frame 1 of main.swf
on your labels layer, create a label for frame 1and call it "movie1", frame 10 label it "movie2", and frame 20 "movie3".
click frame 1 of your actions layer and open your actions panel.

Copy this code
Code: [ Select ]
stop();
if(xx == 1)
{
gotoAndPlay('movie2');
}
else
{
loadMovie("movie1.swf",1);
}
  1. stop();
  2. if(xx == 1)
  3. {
  4. gotoAndPlay('movie2');
  5. }
  6. else
  7. {
  8. loadMovie("movie1.swf",1);
  9. }


Lets break that down.
if(xx == 1) // here we are going to set up an if statement to test for the value of "xx". (In just a moment, we are going to set up a global variable in flv1.swf and set the value of xx equal to 1 so don't worry about where that value is coming from for now).
So when we enter frame 1 of main.swf and xx already has a value of 1 we're going to skip this frame and gotoAndPlay frame 10 (i.e. label movie2). Otherwise we are going to load movie1.swf at level 1 and play your first FLV.


Now open your FLA for movie1 that you created.
Add an actions layer above your FLV Component layer.

Copy this code:
Code: [ Select ]
stop();
_global.xx = 1;
import mx.video.*;
var listenerObject1:Object = new Object();
listenerObject1.cuePoint = function(eventObject:Object):Void {
     var cuePtName = eventObject.info.name;
     if (cuePtName == "end") {
     my_FLVPlybk.loadMovie("main.swf",1);
     
     //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
     //trace("Cue point name is: " + eventObject.info.name);
     //trace("Cue point type is: " + eventObject.info.type);
      }
  };
my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
  1. stop();
  2. _global.xx = 1;
  3. import mx.video.*;
  4. var listenerObject1:Object = new Object();
  5. listenerObject1.cuePoint = function(eventObject:Object):Void {
  6.      var cuePtName = eventObject.info.name;
  7.      if (cuePtName == "end") {
  8.      my_FLVPlybk.loadMovie("main.swf",1);
  9.      
  10.      //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
  11.      //trace("Cue point name is: " + eventObject.info.name);
  12.      //trace("Cue point type is: " + eventObject.info.type);
  13.       }
  14.   };
  15. my_FLVPlybk.addEventListener("cuePoint", listenerObject1);


Let's break that down:
_global.xx = 1; // remember I said we were going to set the value of xx in our flv1 movie and here's where we do it. We want to make it global so it's available throughout.
Next we create a listener object and call it "listenerObject1" If you've worked with listener objects that function should look pretty familiar. *Please Note* For this example, I named my FLVPlayback instance with an instance name of my_FLVPlybk (careful with the spelling). If you have a different instance name for your FLV then change each occurance of my_FLVPlybk about to your instance name.)

If you want to you can uncomment the traces to see what's happening.

OK, so what are we doing here.
When our movie main.swf plays for the first time, flv1.swf hasn't been loaded yet, so the value of xx is null, and as a result we load flv1.swf and start playing it. At the same time we are globally setting the value of xx to 1. as the flv comes to it's end, the event listener picks up the cuepoint "end" and loads main.swf at level one - it's important to keep the level consistently the same, otherwise you might find your flv1 continuing to play at the same time your flv2 does, etc.

Once we've returned to main.swf, this time in frame 1 the value of xx is now 1 so instead of playing flv1 again, now we skip to frame 10 (label movie2).

Are you following the logic?
Now you want to repeat the process above with flv2, only this time for your global variable instead of xx, use yy so we don't confuse things.
Also, in your FLV2 actions, in addition to setting _global.yy = 1; You will also want to reverse what you've done to FLV1 and set _global.xx = 0; (*note* if you don't do this, your value of xx will remain 1 in which case, movie1 will never play again - however where you set this is important - I'll let you play with it a bit to see if you can figure out where and why).

That should be enough for you to work through to where you can get the entire thing to play continuously. Just follow the same logic for FLV3.

Now as far as buttons, add a new layer to main.swf for you buttons.
I'll let you work through the buttons yourself, but basically, for your button actions onRelease, you are going to need to unload the currently playing movie before you gotoAndPlay the next movie, otherwise they'll be playing on top of each other.

I'll let you work with those ideas. If you have any questions or get stuck just ask.
*one last important note* Realize that if you copy the exact code from flv1 actions to your flv2 movie it isn't going to work. Why? because you are loading main.swf after movie 2 plays and it's going to start playing at frame1 of main, not frame 10. and also because you need to globally set the yy variable not the xx variable. Let's see if you can figure out how to get it to return to frame 10. (refer to my note above about setting the global value of xx to 0 as a hint) :D
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Hey Atno/TW,

Wauw what a great answer. I can't try it before monday, but I am sure you really helped me a long way in the right direction.

Best regards
Martin
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

There probably is an easier way, and I haven't even played with doing it in AS3 yet, but I'm sure there's some way you can just do the whole thing in action script and call it from and XML file. I mean I'm sure places like youTube don't do it like I pointed out, but at least I know this way works.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Hey Atno,

I now played arround with it for awhile, but im stuck.

This is what I have done so far:

Cuepoints are ready, each file called flv1.swf etc.

Created a new main.swf with 3 layers

PWS film
Labels
Actions

PWS film is empty(only 3 keyframes at 1 10 20)
Labels has 3 labels (movie1 movie2 movie3)
Actions has following code.

keyframe 1

Code: [ Select ]
 
stop();
if(xx == 1)
{
gotoAndPlay('movie2');
}
else
{
loadMovie("movie1.swf",1);
}
 
  1.  
  2. stop();
  3. if(xx == 1)
  4. {
  5. gotoAndPlay('movie2');
  6. }
  7. else
  8. {
  9. loadMovie("movie1.swf",1);
  10. }
  11.  


keyframe2

Code: [ Select ]
 
stop();
if(yy == 1)
{
gotoAndPlay('movie3');
}
else
{
loadMovie("movie2.swf",10);
}
 
  1.  
  2. stop();
  3. if(yy == 1)
  4. {
  5. gotoAndPlay('movie3');
  6. }
  7. else
  8. {
  9. loadMovie("movie2.swf",10);
  10. }
  11.  


I have changed loadMovie("movie2.swf",10); to 10 and movie2, I dont know if this is correct, but it was my best shot.

Keyframe3 is the same as keyframe2 with a couple of numbers changed.

In flv1.swf I have following actionscript

Code: [ Select ]
 
stop();
_global.xx = 1;
import mx.video.*;
var listenerObject1:Object = new Object();
listenerObject1.cuePoint = function(eventObject:Object):Void {
     var cuePtName = eventObject.info.name;
     if (cuePtName == "end") {
     my_FLVPlybk.loadMovie("main.swf",1);
     
     //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
     //trace("Cue point name is: " + eventObject.info.name);
     //trace("Cue point type is: " + eventObject.info.type);
      }
  };
my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
 
  1.  
  2. stop();
  3. _global.xx = 1;
  4. import mx.video.*;
  5. var listenerObject1:Object = new Object();
  6. listenerObject1.cuePoint = function(eventObject:Object):Void {
  7.      var cuePtName = eventObject.info.name;
  8.      if (cuePtName == "end") {
  9.      my_FLVPlybk.loadMovie("main.swf",1);
  10.      
  11.      //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
  12.      //trace("Cue point name is: " + eventObject.info.name);
  13.      //trace("Cue point type is: " + eventObject.info.type);
  14.       }
  15.   };
  16. my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
  17.  


Same in flv2 and 3, just changed the xx to yy and zz, and the ("main.swf",1) to 10 and 20.

Nothing shows up when I play the main.swf.

But I have a couple of questions.

1. You say the flvplayback should be called my_FLVPlybk. But where? I just gave it an instance name with my_FLVPlybk - is that correct?

2.You call movie1.swf but I dont have a file called that, did i miss something?

3. Am i missing something in main.swf PWS film layer. At this point its just empty.

Sorry for my many questions. I really appriciate your help.

Thanks.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Okay, I changed the movie1.swf til flv1.swf and now the movie is playing trough all 3 movies. - Is this correct?

So far so good.

But I am strugling with the set _global.xx = 0; I cant figure out how to place it correct.

I not started with the buttons yet.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Okay now it seems to work pretty smooth. The 3 movies are playing in a row.

I placed the _global.xx = 0; function in the bottom of flv1.swf action script. Is this correct?

The reason I placed it there is to clear the function after the movie is played.

Now I only need the buttons to work. I am working on it right now but I am strugling with the on relase function.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

Well, think about it logically. onRelease the first thing you want to do is unload the currently playing swf. Then you are going to want to gotoAndStop at the next frame.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Okay I will try :)

I am not very good at the code structure but is it something like this :

First we have the button

button1.onRelease = function() {

}

Then we want to unload the playing swf. This must be main.swf?

unloadMovie(main.swf);

Then we go to the next frame like

gotoAndPlay('movie1');

Am I on the right path? I'll admit I am trying with blindfold
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

right , except I'd suggest using gotoAndStop, vs. gotoAndPlay The action script in frame 2 will load the second movie.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Sorry to write again but it wont work.

I dont understand the gotoandplay vs gotoandstop.

Can you elaborate a little more?
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Is this right?

Code: [ Select ]
 
button1.onRelease = function() {
    gotoAndStop('movie2');
    gotoAndStop('movie3');
    gotoAndPlay('movie1');
}
 
  1.  
  2. button1.onRelease = function() {
  3.     gotoAndStop('movie2');
  4.     gotoAndStop('movie3');
  5.     gotoAndPlay('movie1');
  6. }
  7.  


I thought I had to stop both movie 2 and 3 because i dont know when the user is clicking on button1.

But it won't stop the other movie.

Btw. Was the set _global.xx = 0; placed correct?
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Okay sorry my last reply was stupid.

I only have to use gotoandstop or gotoandplay, I get this now.

But I can't get the unloadmovie to work. Any sugestions?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

Try this for button1
Code: [ Select ]
button1.onRelease = function() {
     unloadMovie(_level1);
     gotoAndStop('movie2');
 }
  1. button1.onRelease = function() {
  2.      unloadMovie(_level1);
  3.      gotoAndStop('movie2');
  4.  }


_level1 is the level of the movie currently playing and should unload it and then jump to frame 2
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Hey Atno,

First of all thank you for all this help.

It seems your code is working fine. But when I make the other buttons like this, it dont work as well.

I think I maybe done something wrong with the set _global.xx = 0; which i placed here:
Code: [ Select ]
stop();
_global.yy = 1;
import mx.video.*;
var listenerObject1:Object = new Object();
listenerObject1.cuePoint = function(eventObject:Object):Void {
    var cuePtName = eventObject.info.name;
    if (cuePtName == "end") {
    my_FLVPlybk.loadMovie("main.swf",10);
    
    //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
    //trace("Cue point name is: " + eventObject.info.name);
    //trace("Cue point type is: " + eventObject.info.type);
     }
};
my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
_global.xx = 0;
  1. stop();
  2. _global.yy = 1;
  3. import mx.video.*;
  4. var listenerObject1:Object = new Object();
  5. listenerObject1.cuePoint = function(eventObject:Object):Void {
  6.     var cuePtName = eventObject.info.name;
  7.     if (cuePtName == "end") {
  8.     my_FLVPlybk.loadMovie("main.swf",10);
  9.     
  10.     //trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
  11.     //trace("Cue point name is: " + eventObject.info.name);
  12.     //trace("Cue point type is: " + eventObject.info.type);
  13.      }
  14. };
  15. my_FLVPlybk.addEventListener("cuePoint", listenerObject1);
  16. _global.xx = 0;
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

I'm actually making an example just for the heck of it since I'll need to do something similar to this for an upcoming project. I'll post it when I have it.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Atno,

If it wasn't because you live over the ocean I would send a good bootle of wine to you :)

Thanks
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

Sorry to take so long to get back with you. I do have the majority of an example working, except having a couple problems with button 2 and 3. Unfortunately I have a work assignment that's going to take me the rest of the day. I'll try to tweak things up and post by the morning.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Hey Atno,

Dont be sorry, you do this for free. I am just glad you will use your sparetime to help me. So take your time.

But if its not a problem for you, it could be interesting to see what you done so far, maybe I could play arround with it and learn :)

If you rather would wait until you are finished, its okay.

Thanks again.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

Yeah, no prob. If you want to mess around with what I have so far, here's the zip

http://www.alaron-nuclear.com/devsite/o ... tonflv.zip

Sorry it's so large. I just used three FLV's I already had existing and they are about 3 minutes long each.

The main movie loops through all three FLV's consecutively as intended if no buttons are pressed. You can use the FLV player controls independently of the main timeline buttons.

Button1 works as intended and I had just started to work on button2 applying the same logic, but it wasn't working and I had to stop work on it for my real job before I had a chance to figure out why. You'll need create and add button3. I hadn't gotten that far. When you do, be sure when you create the button symbol to choose Export for Action Script and Export in First Frame.

Once you get the code working for all three buttons in Frame1 you'll need to add the button segment of the action script to frames 10 and 20 as well. All files were created in CS3, but saved for Flash 8 and AS2.

If I can't get to it tonight, I am off tomorrow and will mess with it then, if you still haven't figured it out.


Thanks for the offer on the wine. *lol. Just toss it in the ocean and I'll pick it up when it floats by the New Jersey coastline *lol.
  • martintygsen
  • Newbie
  • Newbie
  • martintygsen
  • Posts: 14

Post 3+ Months Ago

Thanks, it was a great help, I'm really close now, I only have 1 little problem left.

When using the buttons it all works fine - except when I let the movie play for it self to flv2 and then change back to flv1 via the button. Then flv2 dont stop.

But if i change to flv2 or flv3 before flv1 is done it works fine.

Maybe you have a fix to this - when you have the time.

Btw. look for a bottle of wine with a note on that says THANKS ;)

Post Information

  • Total Posts in this topic: 21 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.