Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE FLASH:HomeFlash ForumFlash TutorialsFlash Video TutorialsWeb Streaming ForumAdobe FlashPodcast

FLVPlayback and ActionScript 3

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Arvid SchneiderFLVPlayback and ActionScript 3
by on Aug 16, 2011 at 2:11:34 pm

I have come a little closer with my project, and still need some help please. I have 5 Flvs which i want to play randomly on this page http://www.music-puppets.com/

The .fla file I have created contains this code:

var files:Array = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv" ];
var shuffledFiles:Array = shuffleArray(files);
//quick test
var testTimer:Timer = new Timer(1000);
testTimer.addEventListener(TimerEvent.TIMER,updateFile);
testTimer.start();

function updateFile(event:TimerEvent):void{
if(shuffledFiles.length == 0) shuffledFiles = shuffleArray(files);//all files played, repeat process
trace('play file',shuffledFiles[0]);
shuffledFiles.shift();
}
function shuffleArray(source:Array,clone:Boolean = true):Array {
var output:Array = [];
var input:Array = clone ? [].concat(source) : source;//clone ? preserve orignal items by making a copy for shuffling, or not
while(input.length) output.push(input.splice(int(Math.random() * input.length-1),1)[0]);
return output;

}



This script works. In the Output every flv is listed randomly, and then repeated. Next up i want this AS Script to work with an FLV Component.

But how to I get that to work?

In my library I have the 5 flvs, and flvplayback component.
I dragged the FLVPlayback component to the stage, but I can only add one flv in the source. How do I get my working actionscript to work with the FLVPlayback component.

Here you can see how my screen looks like.

capture01.jpg

capture02.jpg



Would be great to get some feedback :)

http://www.urs3d.net


Return to posts index
Reply   Like  

Pieter HelsenRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 2:38:21 pm

Easy. Drag the FLV Playback component to the stage. Don't enter a source, but do give the component an instance name.

Then, just do myComponent.play(shuffledFiles[0]);

More info on the FLV component:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/video...

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index
Reply   Like  

Arvid SchneiderRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 2:45:13 pm

Thank you for your quick reply.

where should i " do myComponent.play(shuffledFiles[0]); "


Should I also write it in the actionscript layer?
or where should I place the script "myComponent.play(shuffledFiles[0]);"

if i named the FLVPlayback instance to myComponent?
Thank you very much!

http://www.urs3d.net


Return to posts index
Reply   Like  


Pieter HelsenRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 3:03:48 pm

It would go one line below the following line:


trace('play file',shuffledFiles[0]);


Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index
Reply   Like  

Arvid SchneiderRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 3:06:52 pm

I get some syntax error.
look at the image below



http://www.urs3d.net


Return to posts index
Reply   Like  

Pieter HelsenRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 3:16:30 pm

Remove the 'do' at the beginning of the line of code.

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index
Reply   Like  


Arvid SchneiderRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 3:20:40 pm

Thank you! I feel really really stupid
I and you probably think the same ;)

Okay, now I get no errors. When I Test the movie Ctrl-Enter, the playback window opens but the videos arent playing. Just in the Output windows the traces are shown, which video has been chosen. But the playback window stays blank, like in the image below.



http://www.urs3d.net


Return to posts index
Reply   Like  

Pieter HelsenRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 3:45:50 pm

Is the path to your .flv file correct? Are your .flv files in the same directory as your .swf file?

Other than that, that code should work methinks.

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index
Reply   Like  

Arvid SchneiderRe: FLVPlayback and ActionScript 3
by on Aug 16, 2011 at 3:51:20 pm

Okay, it placed them in the same directory...
The movie plays now.
But each clip doesnt play till the end. It just play as long as it written in the code

var testTimer:Timer = new Timer(1000);
testTimer.addEventListener(TimerEvent.TIMER,updateFile);
testTimer.start();


Now i just have to somehow write, that it should skip to the next video until its finished not after the Timer 1000 (miliseconds I guess)

So if you can help with that too. You are my official flash HERO :)

http://www.urs3d.net


Return to posts index
Reply   Like  


Arvid SchneiderRe: FLVPlayback and ActionScript 3
by on Aug 17, 2011 at 11:24:35 am

If anyone is interested. I have got the running code :)

import flash.events.Event;
import fl.video.*;

var files:Array;
var shuffledFiles:Array;

loaderInfo.addEventListener(Event.COMPLETE,ready);
function ready(event:Event):void{
loaderInfo.removeEventListener(Event.COMPLETE,ready);
//swf rescale setup
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE,stageResized);
//get FlashVars - a string converted into an Array by spliting it on the , character
//if the files FlashVar is setup correctly use the data, else use default values
if(loaderInfo.parameters.files != undefined) files = loaderInfo.parameters.files.indexOf(',') > 0 ? loaderInfo.parameters.files.split(",") : [loaderInfo.parameters.files];
else files = [ "Sz01Puppet.flv", "Sz02Puppet.flv", "Sz03Puppet.flv", "Sz04Puppet.flv", "Sz05Puppet.flv" ];
shuffledFiles = shuffleArray(files);
//play the 1st video
videoPlayer.source = shuffledFiles[0];
shuffledFiles.shift();

//see when the video finished playing
videoPlayer.addEventListener(VideoEvent.COMPLETE,videoFinished);
}
function videoFinished(event:VideoEvent):void{
if(shuffledFiles.length == 0) shuffledFiles = shuffleArray(files);//all files played, repeat process
videoPlayer.source = shuffledFiles[0];//play the first video in the random list
videoPlayer.play();
trace('playing',shuffledFiles[0]);

shuffledFiles.shift();//remove the first video from the random list (e.g. [2,0,1].shift() becomes [0,1])
}
function stageResized(event:Event):void{
videoPlayer.width = stage.stageWidth;
videoPlayer.height = stage.stageHeight;
}
function shuffleArray(source:Array,clone:Boolean = true):Array {
var output:Array = [];
var input:Array = clone ? [].concat(source) : source;//clone ? preserve orignal items by making a copy for shuffling, or not
while(input.length) output.push(input.splice(int(Math.random() * input.length-1),1)[0]);
return output;
}











http://www.urs3d.net


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSMAGAZINESTOCKYARDVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2013 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]