Please could someone have a quick look at my code and tell me what I’m doing wrong.
I’m attempting to create a thumbnail video gallery by reading from XML and attaching each video to the stage with actionscript. Everything works fine and the videos are successfully loaded but the only problem is that none of them play, all I see are still images of the first frame of each video, even though they report that all data has been loaded.
When I use the same code outside the loop to attach a single video to the root timeline it works as expected, but not when placed inside my loop for going through each XML entry.
I’m using a video object stored in my library and then wrapped in a symbol which is duplicated for each thumbnail.
Thanks for the help.
I’m using Flash 8 by the way.
#include "mc_tween2.as"
////////////////////////////////////
// A few configurables
hOffset = 170; // the horizontal distance between each thumb
vOffsetMax = 170; // the maximum vertical deviation (actual deviation controlled randomly)
scaleDeviationMax = 60; // maximum scale deviation, in percent (actual deviation controlled randomly)
////////////////////////////////////
// Set up the hidden MC which will become the zoomed video template
var videotemplate:MovieClip = this.attachMovie("myVideo", "myVideo", 1001); // should be this.getNextHighestDepth() but gets covered by other stuff
videotemplate._x = 250;
videotemplate._y = 300;
videotemplate._alpha = 0;
videotemplate._visible = false;
////////////////////////////////////
// Start doing stuff
loadVideosXML();
//loadPhotosXML();
////////////////////////////////////
// XML data transformations
function loadVideosXML () {
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = processVideosXML;
xmlData.load("videos.xml");
}
function processVideosXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;
video_thumb_url = [];
video_large_url = [];
video_caption = [];
for (i=0; i<total; i++) {
video_thumb_url* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
video_large_url* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
video_caption* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
}
placeVideos();
} else {
content = "file not loaded!";
}
}
function placeVideos() {
startPosX = 0;
startPosY = 30;
numImages = video_large_url.length;
containerAlias = this.createEmptyMovieClip("videoContainer", 0);
// Create a NetConnection object
var my_nc:NetConnection = new NetConnection();
// Create a local streaming connection
my_nc.connect(null);
for (i=0; i<numImages; i++) {
var thisMC:MovieClip = this.videoContainer.attachMovie("video_thumb_template", "video"+i+"_mc", i);
thisMC.thumb_text.thumb_text.text = video_caption*;
thisMC.thumb_text._alpha = 0; // hide the text to start with
thisMC.img_id = i; // stores the image number inside this symbol so we can use it for zooming the correct image
thisMC._x = startPosX;
thisMC._y = startPosY;
thisMC._y = thisMC._y + Math.random() * vOffsetMax;
thisScale = (100 - Math.random() * scaleDeviationMax);
thisMC2._xscale = thisScale;
thisMC2._yscale = thisScale;
_root["ns"+i] = new NetStream(my_nc);
_root["ns"+i].setBufferTime(5);
_root["ns"+i].onStatus = function(oInfo:Object):Void {
trace(oInfo.code);
trace('Loaded: '+this.bytesLoaded+'/'+this.bytesTotal);
}
thisMC.videoThumb.attachVideo(_root["ns"+i]);
// Begin playing the FLV file
_root["ns"+i].play(video_thumb_url*);
///////////////////////////////
// increment the layout position
startPosX = startPosX + hOffset;
}
}