A Flash Developer Resource Site
User Name
Password
Log in
Help
Register
Remember Me?
Forum
What's New?
New Posts FAQ Calendar Forum Actions
Advanced Search
Quick Links
Is your business an energy sap? Learn how to save money by making your data center run efficiently with our eBook.
Is your business an energy sap? Learn how to save money by making your data center run efficiently with our eBook.
HTML5 is the new standard that is expected to take over the Web. Learn why HTML5 is important and discover how to start using it today!
HTML5 is the new standard that is expected to take over the Web. Learn why HTML5 is important and discover how to start using it today!
Forum
Flash Help
Online Video
Play Streaming FLVs in a Random Order
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
Results 1 to 2 of 2
Thread: Play Streaming FLVs in a Random Order
Share
0
Share 0
Tweet
Share
Thread Tools
#1
08-07-2008, 02:29 PM
keirianb
Junior Member
Join Date:
Posts:
Aug 2008
2
Display
Play Streaming FLVs in a Random Order
I had a lot of trouble finding a method for accomplishing this so I thought I would post here. Hope it helps!
My challenge was to write a flash file that would pull in a series of random FLVs and stream each one once. Each time the page is
reloaded the videos should be randomly re-ordered. To sum up:
Load FLVs in a random order
Play all FLVs continuously without repeating
go to an ending frame when all video have played once
THE VIDEOS
To start you need to have a number of videos with Cue Points to signal the end of the FLV. For this method I embedded the Cue
Point into the file when I encoded them into FLV format with CS3 Video Encoder. I named the Cue Point in each video "END" (You
can use AS Cue Points, but you will need to know the runtime of each video. With embedded method you just put the Cue Point
at the end of the video and do not need to know the run-time)
For the purposes of this example I used four (4)videos, but you could use any number.
THE FLASH FILE
The FLA file for the videos are broken up into:
1. A starting frame with Action Script only
2. One (1) frame per video file
3. An ending frame with whatever you decide
To begin:
Create a key frame for your starting frame, each one of you videos, and the ending frame.
CONTENT
Insert a FLVPlayback Component into the first video frame (frame 2) and point it to your first video. Give the Component an
instance name of vid001. Add an instance of each video into the remaining video frames and give the instance the names vid002,
vid003, vid004 (note: you don't have to use that naming scheme, but it will allow you to see where it is refered to in the code.)
For the purposes of testing, insert text into the end frame to let you know the videos have reached the end. You will then give this
frame the name "endFrame".
ACTION SCRIPT
First create a new layer with the same 6 keyframes and put all your AS in this layer.
STARTING FRAME
In your starting frame enter the following code (4 video version):
Code:
//This section creates the array.
var myArray:Array = new Array(2,3,4,5)
//This is the function that randomizes the Array
function randomize(a:Array):Void {
var i:Number = a.length;
if (i > 0) {
while (--i) {
var j:Number = Math.floor(Math.random() * (i + 1));
var tmpi:Object = a[i];
var tmpj:Object = a[j];
a[i] = tmpj;
a[j] = tmpi;
}
}
}
//run the randomize function on the Array
randomize(myArray)
//trace(myArray)
//This section is for the frame count
var frameCount:Number = 0
var checkNumber:Number = 4
//trace(frameCount)
This code will do three things:
It first creates the Array "myArray" and then randomizes it. (The trace statements are in for testing purposes and can be removed
if you wish.)
The second section creates a frameCount number which we will use to track how many video should be played. The checkNumber
should be the same as the number of vidoes in your SWF.
The last bit of code tell the SWF to to gotoAndPlay the fist number in the Array. Since the Array is made up af four numbers, the
SWF will goto that number frame.
VIDEO FRAMES
The video frames will all have the same code, but with two significant differeces. Here is the code for the first video (frame 2)
Code:
stop();
frameCount ++;
//trace(frameCount);
var flvListener:Object = new Object();
flvListener.cuePoint = function(eventObject:Object):Void
if (eventObject.info.name == "END") {
{
if (frameCount != checkNumber ) {
gotoAndPlay(myArray[1]);
} else {
gotoAndPlay("endFrame");
}
}
};
//change vid001 to reflect the FLVPLayback on that frame
vid001.addEventListener("cuePoint",flvListener);
This code does a few things
It first stops the timeline to allow the FLV in that frame to play.
Then it uses "frameCount ++;" to advance the frameCount by 1.
Next it listens for our "END" Cue Point which activates our embedded if/else statement.
The embedded if/else statement says that is the frameCount is not equal to the checkNumber (4 in our case, but however many
videos you have.) to gotoAndPlay the next frame in the array.
This is the first area you will customize for each Video frame. Just make each frame play the next number in the random array. It
doesn't matter what order the frames are played in, becuase they will be referencing the global array and always be random
without repeat.
If the frameCount has reached the checkNumber then the SWF will gotoAndPlay the Frame named endFrame. At this point your
videos will have all played in a random order.
The only other part you will need to customized on each frame is changing the
Code:
vid001.addEventListener("cuePoint",flvListener);
from "vid001" to match the instance name of the FLVPlayback on that frame.
This is my first shot at explaining a process in Flash so I hope it isn't too confusing. If you try this out and it doesn't work or if
you see something I'm missing, please let me know.
-KReply With Quote
08-08-2008, 11:16 AM
#2
keirianb
Junior Member
Join Date:
Posts:
Aug 2008
2
Hey all,
I can't edit the original post, so I wanted to add a quick update. There is a problem with the above method which is really easy to
fix.
For each video frame change the if/then statement to:
Code:
if (eventObject.info.name == "END") {
if (frameCount != checkNumber ) {
gotoAndPlay(myArray[frameCount]);
} else {
gotoAndPlay("endFrame");
}
}
This will make the play order match the array order and ensure that the SWF doesn't jump to the end (which could happen).
This also means that the only line of the code you need to customize is the:
Code:
vid001.addEventListener("cuePoint",flvListener);
This line still needs to point to your FLVPlayback component.
Reply With Quote
Quick Navigation
Online Video
Top
« Previous Thread | Next Thread »
Posting Permissions
You
You
You
You
may
may
may
may
not
not
not
not
post new threads
post replies
post attachments
edit your posts
BB code is On
Smilies are On
[IMG] code is On
[VIDEO] code is On
HTML code is Off
Forum Rules
Contact Us Flash Kit Archive Privacy Statement Top
Cl
Po
Acceptable Use Policy
Property of Quinstreet Enterprise.
Terms of Service | Licensing & Reprints | Privacy Policy | Advertise
Copyright 2016 QuinStreet Inc. All Rights Reserved.
All times are GMT -4. The time now is 03:49 PM.
Powered by vBulletin® Version 4.2.2
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.
© Copyright 2026 Paperzz