i’m trying to setup a listbox conatining a list of movies. what i would like to do is click on a movie name in the list box and change the movie in the container on the stage.
i’ve had a go but no luck and im starting to get mad!!
please help!
i have have included a link to a page which has the .fla file (apparently too big to post here) of my efforts so far (please dont laugh at my actionscript!!)
Erase all your code, remove the container movie clip and create a textfield with the instance name “myTextField”. Place it under the listbox. Now place this code on the timeline:
listbox.addItem("Cloud", "cloud.swf");
listbox.addItem("Flowers", "flowers.swf");
this.createEmptyMovieClip("container", 1);
this.createEmptyMovieClip("temp", 2);
container._x = listbox._x+listbox._width+10;
container._y = listbox._y;
changeMovie = function () {
if (clip != listbox.getSelectedItem().data) {
clip = listbox.getSelectedItem().data;
loadMovie(clip, "container");
preload();
}
};
preload = function () {
temp.onEnterFrame = function() {
var t = container.getBytesTotal(), l = container.getBytesLoaded();
if (t && !isNaN(t)) {
var percent = Math.round(l*100/t);
if (l == t) {
myTextField.text = "Done loading";
this.onEnterFrame = null;
} else {
myTextField.text = "Loading "+percent+" %";
}
}
};
};
listbox.setChangeHandler("changeMovie");
//add items to the listbox
listbox.addItem("Cloud", "cloud.swf");
listbox.addItem("Flowers", "flowers.swf");
//create the container mc
this.createEmptyMovieClip("container", 1);
//create the temp mc, which will handle the swf's preloading
this.createEmptyMovieClip("temp", 2);
//set the coordinates for the container mc
container._x = listbox._x+listbox._width+10;
container._y = listbox._y;
//declare function changeMovie
changeMovie = function () {
//if varible clip is not equal to the selected item of the listbox (this is to avoid loading the same movie 2 times in a row)
if (clip != listbox.getSelectedItem().data) {
//store the selected item of the listbox in the variable clip
clip = listbox.getSelectedItem().data;
//load movie into the container mc
loadMovie(clip, "container");
//call the preload function
preload();
}
};
//declare function preload
preload = function () {
//declare the onEnterFrame handler for the temp mc
//everything inside the onEnterFrame will be continually triggered at the frame rate of the movie
temp.onEnterFrame = function() {
//t is the total bytes of the clip being loaded
//l is the total bytes loaded of the clip being loaded
var t = container.getBytesTotal(), l = container.getBytesLoaded();
//checking if the total bytes of the clip being loaded is a number
if (t && !isNaN(t)) {
//percent is the percentage of bytes loaded
var percent = Math.round(l*100/t);
//if its fully loaded
if (l == t) {
//set the textfield text equal to "Done loading"
myTextField.text = "Done loading";
//empty the onEnterFrame handler
this.onEnterFrame = null;
//if its not fully loaded
} else {
//outputs the percentage of bytes loaded
myTextField.text = "Loading "+percent+" %";
}
}
};
};
//setChange Handler specifies a change handler to call when the selection in the list box changes.
//In this case, call the function changeMovie
listbox.setChangeHandler("changeMovie");