javascript/HTML var to flash SWF file
Discussion
Hi im trying to pass a filename to flash so i can stream videos (security camera videos i have indexed on my server)
EDIT: Sorry the top block of code wont add - any tips and i will hapily make change to thread to get it wihtin code box.
Flash Actionscript
{{{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var _vidName = _vidNamevar;
var _vidURL = "http://www.xxxx.com/cammonitor/stream/flvprovider.php?file=" + _vidName;
var _phpURL = "http://www.xxxx.com/cammonitor/stream/flvprovider.php";
var ending = false;
var amountLoaded:Number;
var duration:Number;
var loaderwidth = loader.loadbar._width;
theVideo.attachVideo(ns);
ns.setBufferTime(2);
statusID = setInterval(videoStatus, 200);
ns.onStatus = function(info) {
trace(info.code);
if(info.code == "NetStream.Buffer.Full"
{
bufferClip._visible = false;
ending = false;
clearInterval( statusID );
statusID = setInterval(videoStatus, 200);
}
if(info.code == "NetStream.Buffer.Empty"
{
if ( !ending ) {
bufferClip._visible = true;
}
}
if(info.code == "NetStream.Play.Stop"
{
bufferClip._visible = false;
//ending = true;
}
if(info.code == "NetStream.Play.Start"
{
ending = false;
}
if(info.code == "NetStream.Buffer.Flush"
{
ending = true;
}
}
playButton.onRelease = function() {
ns.pause();
}
play_btn.onRelease = function() {
restartIt();
this._visible = false;
}
rewindButton.onRelease = function() {
restartIt();
}
ns["onMetaData"] = function(obj) {
duration = obj.duration;
//trace(obj.width);
//trace(obj.height);
// suck out the times and filepositions array, this was added by flvmdi27b
times = obj.keyframes.times;
positions = obj.keyframes.filepositions;
}
function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * loaderwidth;
loader.scrub._x = ns.time / duration * loaderwidth;
}
loader.scrub.onPress = function() {
clearInterval (statusID );
ns.pause();
this.startDrag(false,0,this._y,loaderwidth,this._y);
}
loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
scrubit();
this.stopDrag();
}
function scrubit() {
var tofind = Math.floor((loader.scrub._x/loaderwidth)*duration);
if (tofind <= 0 ) {
restartIt();
return;
}
for (var i:Number=0; i < times.length; i++){
var j = i + 1;
if( (times[i] <= tofind) && (times[j] >= tofind ) ){
trace("match at " + times[i] + " and " + positions[i]);
bufferClip._visible = true;
ns.play( _phpURL + "?file=" + _vidName + "&position=" + positions[i]);
trace("play " + _phpURL + "?file=" + _vidName + "&position=" + positions[i]);
break;
}
}
}
function pauseIt() {
ns.pause();
}
function stopIt() {
ns.seek(0);
ns.pause();
}
function restartIt() {
ns.play( _vidURL );
}
//restartIt();
// holds sound
_root.createEmptyMovieClip("vSound",_root.getNextHighestDepth());
vSound.attachAudio(ns);
var so:Sound = new Sound(vSound);
so.setVolume(100);
mute.onRollOver = function() {
if(so.getVolume()== 100) {
this.gotoAndStop("onOver"
;
}
else {
this.gotoAndStop("muteOver"
;
}
}
mute.onRollOut = function() {
if(so.getVolume()== 100) {
this.gotoAndStop("on"
;
}
else {
this.gotoAndStop("mute"
;
}
}
mute.onRelease = function() {
if(so.getVolume()== 100) {
so.setVolume(0);
this.gotoAndStop("muteOver"
;
}
else {
so.setVolume(100);
this.gotoAndStop("onOver"
;
}
}
/*
var theMenu:ContextMenu = new ContextMenu();
theMenu.hideBuiltInItems();
_root.menu = theMenu;
var item1:ContextMenuItem = new ContextMenuItem("::::: Video Controls :::::",trace);
theMenu.customItems[0] = item1;
var item2:ContextMenuItem = new ContextMenuItem("Play / Pause Video",pauseIt,true);
theMenu.customItems[1] = item2;
var item3:ContextMenuItem = new ContextMenuItem("Replay the Video",restartIt);
theMenu.customItems[2] = item3;
}}}
HTML/test.php
As you can see i've tried multiple ways of sending the var and neither work.
Now i know this isn't passing a value to the variable as in flvprovider.php i exec("echo $file >> file.txt"
; and it returns "/home/www/cammonitor/stream/undefined" but if i set the var within the flash file "var _vidName = 'golfers.flv'" then it returns "var _vidName = _vidNamevar;"
Do i need anything extra in the flash file to define the variable as comming from the url string?
Regards
Liam
EDIT: Sorry the top block of code wont add - any tips and i will hapily make change to thread to get it wihtin code box.
Flash Actionscript
{{{
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var _vidName = _vidNamevar;
var _vidURL = "http://www.xxxx.com/cammonitor/stream/flvprovider.php?file=" + _vidName;
var _phpURL = "http://www.xxxx.com/cammonitor/stream/flvprovider.php";
var ending = false;
var amountLoaded:Number;
var duration:Number;
var loaderwidth = loader.loadbar._width;
theVideo.attachVideo(ns);
ns.setBufferTime(2);
statusID = setInterval(videoStatus, 200);
ns.onStatus = function(info) {
trace(info.code);
if(info.code == "NetStream.Buffer.Full"
{bufferClip._visible = false;
ending = false;
clearInterval( statusID );
statusID = setInterval(videoStatus, 200);
}
if(info.code == "NetStream.Buffer.Empty"
{if ( !ending ) {
bufferClip._visible = true;
}
}
if(info.code == "NetStream.Play.Stop"
{bufferClip._visible = false;
//ending = true;
}
if(info.code == "NetStream.Play.Start"
{ending = false;
}
if(info.code == "NetStream.Buffer.Flush"
{ending = true;
}
}
playButton.onRelease = function() {
ns.pause();
}
play_btn.onRelease = function() {
restartIt();
this._visible = false;
}
rewindButton.onRelease = function() {
restartIt();
}
ns["onMetaData"] = function(obj) {
duration = obj.duration;
//trace(obj.width);
//trace(obj.height);
// suck out the times and filepositions array, this was added by flvmdi27b
times = obj.keyframes.times;
positions = obj.keyframes.filepositions;
}
function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * loaderwidth;
loader.scrub._x = ns.time / duration * loaderwidth;
}
loader.scrub.onPress = function() {
clearInterval (statusID );
ns.pause();
this.startDrag(false,0,this._y,loaderwidth,this._y);
}
loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
scrubit();
this.stopDrag();
}
function scrubit() {
var tofind = Math.floor((loader.scrub._x/loaderwidth)*duration);
if (tofind <= 0 ) {
restartIt();
return;
}
for (var i:Number=0; i < times.length; i++){
var j = i + 1;
if( (times[i] <= tofind) && (times[j] >= tofind ) ){
trace("match at " + times[i] + " and " + positions[i]);
bufferClip._visible = true;
ns.play( _phpURL + "?file=" + _vidName + "&position=" + positions[i]);
trace("play " + _phpURL + "?file=" + _vidName + "&position=" + positions[i]);
break;
}
}
}
function pauseIt() {
ns.pause();
}
function stopIt() {
ns.seek(0);
ns.pause();
}
function restartIt() {
ns.play( _vidURL );
}
//restartIt();
// holds sound
_root.createEmptyMovieClip("vSound",_root.getNextHighestDepth());
vSound.attachAudio(ns);
var so:Sound = new Sound(vSound);
so.setVolume(100);
mute.onRollOver = function() {
if(so.getVolume()== 100) {
this.gotoAndStop("onOver"
;}
else {
this.gotoAndStop("muteOver"
;}
}
mute.onRollOut = function() {
if(so.getVolume()== 100) {
this.gotoAndStop("on"
;}
else {
this.gotoAndStop("mute"
;}
}
mute.onRelease = function() {
if(so.getVolume()== 100) {
so.setVolume(0);
this.gotoAndStop("muteOver"
;}
else {
so.setVolume(100);
this.gotoAndStop("onOver"
;}
}
/*
var theMenu:ContextMenu = new ContextMenu();
theMenu.hideBuiltInItems();
_root.menu = theMenu;
var item1:ContextMenuItem = new ContextMenuItem("::::: Video Controls :::::",trace);
theMenu.customItems[0] = item1;
var item2:ContextMenuItem = new ContextMenuItem("Play / Pause Video",pauseIt,true);
theMenu.customItems[1] = item2;
var item3:ContextMenuItem = new ContextMenuItem("Replay the Video",restartIt);
theMenu.customItems[2] = item3;
- /
}}}
HTML/test.php
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','380','height','260','src','scrubber','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','scrubber' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="380" height="260">
<param name="movie" value="scrubber.swf?_vidnamevar=golfers.flv">
<param name="_vidnamevar" value="golfers.flv">
<param name="FlashVars" VALUE="_vidnamevar=golfers.flv">
<param name="quality" value="high">
<embed src="scrubber.swf?__vidnamevar=golfers.flv?_vidnamevar=golfers.flv" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="380" height="260" FlashVars="_vidnamevar=golfers.flv" ></embed>
</object>
</noscript></body>
</html>
As you can see i've tried multiple ways of sending the var and neither work.
Now i know this isn't passing a value to the variable as in flvprovider.php i exec("echo $file >> file.txt"
; and it returns "/home/www/cammonitor/stream/undefined" but if i set the var within the flash file "var _vidName = 'golfers.flv'" then it returns "var _vidName = _vidNamevar;"Do i need anything extra in the flash file to define the variable as comming from the url string?
Regards
Liam
Edited by shocker-z on Wednesday 14th November 16:51
Edited by shocker-z on Wednesday 14th November 16:52
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


