Spaantje
%Europe/Berlin %377 %2007, 10:03
Hallo,
Ik heb een probleem met de Loading Bar van Flash.
Ik maak gebruik van een script om vanuit een XML bestand een lijst te halen waarin staat welke filmpjes geimporteerd moeten worden (nagemaakt op basis van de Sample van Flash Gallery Tween). Alleen nou wil ik niet zoals in dat bestand staat een balk voor elk geimporteerd bestand een loading bar hebben. Maar gewoon 1 algemene.
En dat wil niet lukken. Ik krijg het alleen maar voor elkaar om een loading bar te maken die de laattijd van de eerste laat zien.
Zou iemand mij (op weg) kunnen helpen??
Alvast bedankt!!!
Hieronder de AS code voor het importeren:
my_pb._visible = true;
import mx.transitions.Tween;
import mx.transitions.easing.Regular;
// Set the starting X and Y positions for the gallery images.
_global.thisX = 30;
_global.thisY = 200;
/* Set static values for the Stage's width and height.
Using Stage.width and Stage.height within the code results in
strangely positioned full images when testing in the Flash environment
(but the problem doesn't exist when published to a SWF file). */
_global.stageWidth = 970;
_global.stageHeight = 550;
// create array to hold data
var dataArr = new Array();
// XML object
dataXML = new XML();
dataXML.ignoreWhite = true;
dataXML.onLoad = function (success:Boolean) {
// this function takes care of the XML-data
if (success) {
// data loaded in successfully
// put XML data into dataArr
var d = this.firstChild;
dataLen = d.childNodes.length;
_global.aantal = Number(dataLen);
trace("----------------------------------------------------------------------");
trace("Aantal Clipjes: " + dataLen);
// loop over childNodes
for (var i=0;i<dataLen;i++) {
// get childNode
var cNode = d.childNodes[i];
// fill dataArr
dataArr[i] = {};
dataArr[i].href = cNode.attributes.href;
dataArr[i].swf = cNode.attributes.swf;
// trace("----------------------------------------------------------------------");
// trace("Array Href" +i+ ": " + dataArr[i].href);
// trace("Array Swf" +i+ ": " + dataArr[i].swf);
}
// remove XML object as much as possible
d.removeNode();
// Place Gallery
displayGallery(dataArr);
} else {
// failure to load in data successfully
throw new Error("Unable to parse XML");
}
}
dataXML.load("test_short_movies.xml");
/* ------------------------------------------------------------------------------------------------------------------ */
/* create a function which loops through the images in an array,
and creates new movie clips on the Stage. */
function displayGallery(dataArr:Array) {
var galleryLength:Number = dataArr.length;
var movieclip_names_array = new Array();
// loop through each of the images in the gallery_array.
for (var i = 0; i<galleryLength; i++) {
//Progress Bar
/* create a movie clip instance which holds the image. We'll also set a variable,
thisMC, which is an alias to the movie clip instance. */
var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
/* Set Alpha 0% */
movieclip_names_array[i] = thisMC;
movieclip_names_array[i]._alpha = 0;
/* load the current image source into the new movie clip instance,
using the MovieClipLoader class. */
mcLoader_mcl.loadClip(dataArr[i].swf, thisMC);
// attach the preloader symbol from the Library onto the Stage.
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
/* set the preloader's bar_mc's _xscale property to 0%
and set a default value in the progress bars text field. */
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
// set the _x and _y coordinates of the new movie clip.
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
// set the position of the image preloader.
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY;
// if you've displayed 9 columns of images, start a new row.
if ((i+1)%9 == 0) {
// reset the X and Y positions
_global.thisX = 30;
_global.thisY += 60;
// trace("new X Pos: " + _global.thisX);
// trace("new Y Pos: " + _global.thisY);
} else {
_global.thisX += 80+10;
// trace("new X Pos: " + _global.thisX);
}
}
}
// define the MovieClipLoader instance and MovieClipLoader listener Object.
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};
// while the content is preloading, modify the width of the progress bar.
mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
// create a shortcut for the path to the preloader movie clip.
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
my_pb.setProgress(pctLoaded, 100);
};
// when the onLoadInit event is thrown, you're free to position the instances
mclListener.onLoadInit = function(evt:MovieClip) {
my_pb._visible = false;
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
var movieclip_name:String = evt._parent["image"+evt.getDepth()+"_mc"];
var tween1:Tween = new Tween(movieclip_name, "_alpha", Regular.easeOut, 0, 100, 50);
/* set local variables for the target movie clip's width and height,
and the desired settings for the image stroke and border. */
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
/* Diepte opvragen */
var diepte:Number = evt.getDepth();
evt.scale = 100;
/* scale the target movie clip so it appears as a thumbnail.
This allows users to quickly view a full image without downloading it every time,
but unfortunaltey also causes a large initial download. */
evt._xscale = evt.scale;
evt._yscale = evt.scale;
/* On MouseOver Start Play */
evt.onRollOver = function() {
this.play();
}
evt.onRollOut = function() {
// this.stop(1);
}
evt.onRelease = function() {
trace("----------------------------------------------------------------------");
trace("Name: " + evt._name);
trace("Depth: " + diepte);
trace("Url: " + dataArr[Number(diepte)].href);
var myLink:String = dataArr[Number(diepte)].href;
getURL('' + String(myLink) + '');
};
// if the mouse cursor was released outside of the movie clip, call the onRelease handler.
// evt.onReleaseOutside = evt.onRelease;
};
mcLoader_mcl.addListener(mclListener);
/* Hieronder het XML bestand wat ik gebruik */
<?xml version="1.0"?>
<gallery>
<data href="pages.php?name=abn" swf="movies_swf_test_short/abn_amro.swf"></data>
<data href="pages.php?name=andrea" swf="movies_swf_test_short/andrea_bocelli.swf"></data>
<data href="pages.php?name=great_palaces" swf="movies_swf_test_short/great_palaces_of_the_world.swf"></data>
<data href="pages.php?name=nijntje" swf="movies_swf_test_short/nijntje.swf"></data>
<data href="pages.php?name=smit_clyde" swf="movies_swf_test_short/smit_clyde.swf"></data>
<data href="pages.php?name=vision_heal" swf="movies_swf_test_short/a_vision_to_heal.swf"></data>
<data href="pages.php?name=great_castles" swf="movies_swf_test_short/great_castles_of_europe.swf"></data>
<data href="pages.php?name=jongert_regatta" swf="movies_swf_test_short/Jongert_Regatta.swf"></data>
<data href="pages.php?name=treasures_earth" swf="movies_swf_test_short/treasures_of_the_earth.swf"></data>
<data href="pages.php?name=tycoons_nike" swf="movies_swf_test_short/tycoons_nike.swf"></data>
</gallery>
Ik heb een probleem met de Loading Bar van Flash.
Ik maak gebruik van een script om vanuit een XML bestand een lijst te halen waarin staat welke filmpjes geimporteerd moeten worden (nagemaakt op basis van de Sample van Flash Gallery Tween). Alleen nou wil ik niet zoals in dat bestand staat een balk voor elk geimporteerd bestand een loading bar hebben. Maar gewoon 1 algemene.
En dat wil niet lukken. Ik krijg het alleen maar voor elkaar om een loading bar te maken die de laattijd van de eerste laat zien.
Zou iemand mij (op weg) kunnen helpen??
Alvast bedankt!!!
Hieronder de AS code voor het importeren:
my_pb._visible = true;
import mx.transitions.Tween;
import mx.transitions.easing.Regular;
// Set the starting X and Y positions for the gallery images.
_global.thisX = 30;
_global.thisY = 200;
/* Set static values for the Stage's width and height.
Using Stage.width and Stage.height within the code results in
strangely positioned full images when testing in the Flash environment
(but the problem doesn't exist when published to a SWF file). */
_global.stageWidth = 970;
_global.stageHeight = 550;
// create array to hold data
var dataArr = new Array();
// XML object
dataXML = new XML();
dataXML.ignoreWhite = true;
dataXML.onLoad = function (success:Boolean) {
// this function takes care of the XML-data
if (success) {
// data loaded in successfully
// put XML data into dataArr
var d = this.firstChild;
dataLen = d.childNodes.length;
_global.aantal = Number(dataLen);
trace("----------------------------------------------------------------------");
trace("Aantal Clipjes: " + dataLen);
// loop over childNodes
for (var i=0;i<dataLen;i++) {
// get childNode
var cNode = d.childNodes[i];
// fill dataArr
dataArr[i] = {};
dataArr[i].href = cNode.attributes.href;
dataArr[i].swf = cNode.attributes.swf;
// trace("----------------------------------------------------------------------");
// trace("Array Href" +i+ ": " + dataArr[i].href);
// trace("Array Swf" +i+ ": " + dataArr[i].swf);
}
// remove XML object as much as possible
d.removeNode();
// Place Gallery
displayGallery(dataArr);
} else {
// failure to load in data successfully
throw new Error("Unable to parse XML");
}
}
dataXML.load("test_short_movies.xml");
/* ------------------------------------------------------------------------------------------------------------------ */
/* create a function which loops through the images in an array,
and creates new movie clips on the Stage. */
function displayGallery(dataArr:Array) {
var galleryLength:Number = dataArr.length;
var movieclip_names_array = new Array();
// loop through each of the images in the gallery_array.
for (var i = 0; i<galleryLength; i++) {
//Progress Bar
/* create a movie clip instance which holds the image. We'll also set a variable,
thisMC, which is an alias to the movie clip instance. */
var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
/* Set Alpha 0% */
movieclip_names_array[i] = thisMC;
movieclip_names_array[i]._alpha = 0;
/* load the current image source into the new movie clip instance,
using the MovieClipLoader class. */
mcLoader_mcl.loadClip(dataArr[i].swf, thisMC);
// attach the preloader symbol from the Library onto the Stage.
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
/* set the preloader's bar_mc's _xscale property to 0%
and set a default value in the progress bars text field. */
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
// set the _x and _y coordinates of the new movie clip.
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
// set the position of the image preloader.
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY;
// if you've displayed 9 columns of images, start a new row.
if ((i+1)%9 == 0) {
// reset the X and Y positions
_global.thisX = 30;
_global.thisY += 60;
// trace("new X Pos: " + _global.thisX);
// trace("new Y Pos: " + _global.thisY);
} else {
_global.thisX += 80+10;
// trace("new X Pos: " + _global.thisX);
}
}
}
// define the MovieClipLoader instance and MovieClipLoader listener Object.
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};
// while the content is preloading, modify the width of the progress bar.
mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
// create a shortcut for the path to the preloader movie clip.
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
my_pb.setProgress(pctLoaded, 100);
};
// when the onLoadInit event is thrown, you're free to position the instances
mclListener.onLoadInit = function(evt:MovieClip) {
my_pb._visible = false;
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
var movieclip_name:String = evt._parent["image"+evt.getDepth()+"_mc"];
var tween1:Tween = new Tween(movieclip_name, "_alpha", Regular.easeOut, 0, 100, 50);
/* set local variables for the target movie clip's width and height,
and the desired settings for the image stroke and border. */
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
/* Diepte opvragen */
var diepte:Number = evt.getDepth();
evt.scale = 100;
/* scale the target movie clip so it appears as a thumbnail.
This allows users to quickly view a full image without downloading it every time,
but unfortunaltey also causes a large initial download. */
evt._xscale = evt.scale;
evt._yscale = evt.scale;
/* On MouseOver Start Play */
evt.onRollOver = function() {
this.play();
}
evt.onRollOut = function() {
// this.stop(1);
}
evt.onRelease = function() {
trace("----------------------------------------------------------------------");
trace("Name: " + evt._name);
trace("Depth: " + diepte);
trace("Url: " + dataArr[Number(diepte)].href);
var myLink:String = dataArr[Number(diepte)].href;
getURL('' + String(myLink) + '');
};
// if the mouse cursor was released outside of the movie clip, call the onRelease handler.
// evt.onReleaseOutside = evt.onRelease;
};
mcLoader_mcl.addListener(mclListener);
/* Hieronder het XML bestand wat ik gebruik */
<?xml version="1.0"?>
<gallery>
<data href="pages.php?name=abn" swf="movies_swf_test_short/abn_amro.swf"></data>
<data href="pages.php?name=andrea" swf="movies_swf_test_short/andrea_bocelli.swf"></data>
<data href="pages.php?name=great_palaces" swf="movies_swf_test_short/great_palaces_of_the_world.swf"></data>
<data href="pages.php?name=nijntje" swf="movies_swf_test_short/nijntje.swf"></data>
<data href="pages.php?name=smit_clyde" swf="movies_swf_test_short/smit_clyde.swf"></data>
<data href="pages.php?name=vision_heal" swf="movies_swf_test_short/a_vision_to_heal.swf"></data>
<data href="pages.php?name=great_castles" swf="movies_swf_test_short/great_castles_of_europe.swf"></data>
<data href="pages.php?name=jongert_regatta" swf="movies_swf_test_short/Jongert_Regatta.swf"></data>
<data href="pages.php?name=treasures_earth" swf="movies_swf_test_short/treasures_of_the_earth.swf"></data>
<data href="pages.php?name=tycoons_nike" swf="movies_swf_test_short/tycoons_nike.swf"></data>
</gallery>