Flash Final....first shaky steps toward completion
Over the past week, we figured out how to dynamically load .flv files into a .swf using the netStream and netConnection objects. We also have written the necessary perl scripts to communicate with flash and our database in order to send comments, tags and timecode variables as well as to send the path of .flv files on the server into the embedded .swf in the video forum. Example (looks pretty bad still but special thanks to Jadie for some css help at the last minute).
Most of the rest of the project is still in code only:
Flash code:
/*
* Catherine Colman and Nanna Halinen
* with source code by Alex Bisceglie (thankyou!!!)
*
*/
import flash.display.BitmapData;
import flash.geom.Rectangle;
serverpath = "hhtp://www.free4md.com/"; //live path
//variable coming from perl
videoPlay = new LoadVars();
//define perl script
videoPlayScript = serverpath + "sendhttp.pl";
//load
videoPlay.load(videoPlayScript);
//onload?
videoPlay.onLoad = function(){
thisVideo.text = videoPlay.videoData;
}
//create a new NetConnection to dynamically load .flv files
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream = new NetStream(connection_nc);
stream_ns.setBufferTime(3);
video1_video.attachVideo(stream_ns, 1);
//new loadvars for sending user input
commentSend = new LoadVars();
//perl script receiving input
//set comment bar visibility equal to false
commentBar_mc._visible = false;
var mClip_pos_x = 10;
var mClip_pos_y = 10;
var mClip_wid = 100;
var mClip_hei = 100;
// define screen-shot position (x, y)
var sClip_pos_x = 0;
var sClip_pos_y = 10;
// sourceMC is the movieclip where the linked asset get attached to
//var sourceMC:MovieClip = createEmptyMovieClip("sourceMC", 1);
// timeline prog bar
//var timeBarMC:MovieClip = createEmptyMovieClip("timeBarMC", 2);
// destMC is the movieclip where the composite of the loaded mc and previous screengrab are loaded
var destMC:MovieClip = commentBar_mc.createEmptyMovieClip("destMC", 3);
// a bitmapData used to store the screengrab
var screenShot = new BitmapData(mClip_wid, mClip_hei, true, 0);
drawClip();
//------------------------------------------->
function drawClip() {
//load video variable
stream_ns.play(thisVideo);
//trace("clip has been loaded");
//trace(_root.sourceMC.bMovie._x);
//timeBarMC.attachMovie("timeLineBar", "timeLineBar_mc", this.getNextHighestDepth());
//timeBarMC.timeLineBar_mc._x = 10;
//timeBarMC.timeLineBar_mc._y = 200;
}
//------------------------------------------->
// Shit from sephiroth
//------------------------------------------->
/*
var listener:Object = new Object();
// copy in progress...
listener.onProgress = function(target:MovieClip, loaded:Number, total:Number) {
var perc = Math.round((loaded/total)*100);
loader.label = "computing... "+perc+"%";
loader.value = perc;
};
// copy is complete, send the result LoadVars to PHP
listener.onComplete = function(target:MovieClip, load_var:LoadVars) {
loader.label = "sending to php...";
load_var.send("files/pixels.php", "_blank", "POST");
loader.close();
};
//
//
function print_me(){
video_mc.pause() // first pause the playing video
pn = new PrintScreen(); // initialize the PrintScreen class
pn.addListener( listener ); // assign a listener
pn.print(_root, 0, 0, 500, 210) // copy the _root
loader.label = "computing... 0%"
loader.open(true, true, true); // open a loader
}
*/
//------------------------------------------->
function grab() {
// draw the new bone into the screenshot bitmapData
screenShot.draw(video1_video);
// and paste it into the top movieclip
commentBar_mc.destMC.attachBitmap(screenShot, 1);
commentBar_mc.destMC._x = sClip_pos_x;
commentBar_mc.destMC._y = sClip_pos_y;
//trace("destMC._width: "+destMC._width);
//trace("d y: "+destMC._y);
}
video1_video.onRelease = function() {
// take the screenshot at mouse_start_x, mouse_start_y for mouse_end_x, mouse_end_y
//takeShot(20, 20, 20, 20);
_root.video1_video.stream_ns.stop();
//grab();
commentOn();
};
//
function commentOn() {
commentBar_mc._visible = true;
grab();
//commentCont_mc.attachMovie("commentBar", "commentBar_mc", this.getNextHighestDepth());
var cName:String = null;
var cText:String = null;
var cImg:String = null;
var cFrame:Number = 0;
//
//trace(commentCont_mc.commentBar_mc.submit_btn._y);
submitBtnListener = new Object();
submitBtnListener.click = function(evt) {
_root.video1_video.stream_ns.play();
cName = commentBar_mc.cName_txt.text;
cText = commentBar_mc.cText_txt.text;
commentBar_mc._visible = false;
//cImg = ;
//cFrame = ;
//
if (cName != "" && cName != "Name" && cName != undefined && cText != "" && cText != "Comment" && cText != undefined) {
postComment(cName, cText, cImg, cFrame);
//pn = new PrintScreen();
//pn.print(commentBar_mc.destMC, 0, 0, 500, 210)
}
};
commentBar_mc.submit_btn.addEventListener("click", submitBtnListener);
cancelBtnListener = new Object();
cancelBtnListener.click = function(evt) {
//trace("comment cancelled");
commentBar_mc._visible = false;
_root.video1_video.stream_ns.play();
};
commentBar_mc.cancel_btn.addEventListener("click", cancelBtnListener);
//
postComment = function (c_Name, c_Text, c_Img, c_Frame) {
commentSend.userComment = userComment.text;
commentSend.userTag = userTag.text;
commentSend.timecode = timecode.text;
myUrlString = commentSend.toString();
textSend.text = myUrlString;
serverscript = serverpath + "flashtodatabase.pl";
//send
commentSend.sendAndLoad(serverscript.commentSend,"POST");
};
commentSend.onLoad = function(){
myCommentString = commentSend.toString();
textComment.text = myCommentString;
if (length(commentSend.stausMsg)>0){
textComment.text = commentSend.statusMsg;
}
}
//
this.onEnterFrame = function() {
//trace(_root.video1_video.stream_ns._currentframe);
//timeBarMC.timeLineBar_mc.pBar._width = ((_root.sourceMC.bMovie._currentframe)/(_root.sourceMC.bMovie._totalframes))*200;
};