Lives On Board

/ My MetaSphere /

Wed Feb 4, 2004

Flash MX Hosting
Web Hosting
Web Tools
Help FAQ
Marketing
Portfolio
Contact
Site Chat
Web Search
Asheville NC
NEW!!Boards
Network Log
Got Flash?
Web Links

Need Help?
We are online if image is green.
We are online if this image is green. Click here to chat live with metasphere.net.

Linux Web Hosting

Flash Hosting with MetaSphere

Today in History:
1941: The United Service Organizations, popularly known as the USO, was chartered.

Metasphere.net
Asheville, NC
Help/FAQ Index / Search
Help/FAQ
Previous Page in Help/FAQ Tour Next Page in Help/FAQ Tour
Return to Main Page in Help/FAQ

Retrieving FLV length via ActionScript

If you want to retrieve the length of your streamed FLV file, you've got some work to do. The only way you can retrieve this value via Flash is by calling a server-side ActionScript. Once you master ServerSide ActionScripting in Flash, you will be considered an MX Jedi. Tons of new features and trick will be at your disposal. To get you started, we'll be retrieving the length of our Flash streamed movie file "timescape.flv". This flv file should be uploaded to the FCS server. Place it inside of UserName/streams/video/timescape.flv. Two seperate pieces we'll be building here. The Flash swf file which displays the movie to your audience, and the backside server ActionScript. The ActionScript is called "main.asc". FCS automatically looks for this file when your app starts. There is no need to call or require or load main.asc in your swf app. By uploading it to your UserName directory, it is called by all of your FCS applications automatically.

FCS CLIENT SIDE ACTION SCRIPT

Here's the client-side ActionScript. This code goes in your swf file. Because you are using absolute paths to your UserName folder, you can run/publish this swf from anywhere. Even locally to help you learn. All that is required on the main stage is a dynamic textbox called output. Make it multilined so you cann see what the server is saying. You can also place a new blank embedded video object on the Stage if you want. This will actually play the movie timescape.flv. This is not neccessary but it looks pretty. Name the new video object you created "MyVideo". Of course to run this example, you will also need to make an FLV file (see above).


//In frame 1 of the main stage of your movie.
#include "NetDebug.as"
app_nc=new NetConnection();
app_nc.connect("rtmp://66.216.97.115/UserName/video");
NewStream=new NetStream(app_nc);
MyVideo.attachVideo(NewStream);
NewStream.play("timescape");

function setupStream(nc){
myStream = new NetStream(nc);
output = output+"CALL getLength"+newline;
trace(output);
/////
myStream = {};
myStream.onResult = function(streamLength){
output = streamLength;
};
nc.call("getLength", myStream, "timescape");
trace(output);
}
app_nc.onStatus = function(info){
output = output+"onStatus="+info.code+newline;
if(info.code == "NetConnection.Connect.Success"){
output = output+"Setupstream"+newline;
setupStream(this);
}
};

FCS SERVER SIDE ACTION SCRIPT

On the server, you will need the following script inside of your main.asc file. Below is a working example of main.asc. Place this file in your UserName folder. Make sure it is called "main.asc". This file is expandable also. You can add your own Client.prototype calls. See your ActionScript Ref Guide for the 50 or so server-side Jedi tricks.

//UserName/main.asc
application.onAppStart = function(){
trace("::: Application has started :::");
}
application.onConnect = function(client){
trace("onConnect:"+client);
application.acceptConnection(client);
Client.prototype.getLength = function(streamName){
trace("gettingLength of"+streamName+":"+Stream.length(streamName));
return Stream.length(streamName);
};
}



Refresh / Add Page to favorites/bookmarks.