Ask a Question related to Macromedia Flash Actionscript, Design and Development.
-
jkoxvold webforumsuser@macromedia.com #1
Re: Help with preloading jpg!!!
kglad wrote:
"your preloader will need to be in a loop of some kind, but it can't be in a for-loop or while-loop."
i'm trying to do something kinda similar. the aim is for the movie to load a sequentially-numbered batch of jpgs from the same folder. that's working fine, except that i want it to load them in sequence and create an icon for each before moving onto the next jpg.
but i'm working with a for loop and it's not giving me love. the code's below; can anyone shed any light on the matter? any help would be much appreciated.
// set the number of images here
nr = 36;
// positions intro clip at the display depth
// for some reason, this doesn't work. going to create an empty movie clip instead
// intro.setDepthTo(150);
createEmptyMovieClip("intro",150);
setProperty(intro, _x, 102);
setProperty(intro, _y, 137);
loadMovie("intro.swf", intro);
// creates empty movie clips into which to load the images
i = 1;
for (i; i<=nr; i++){
createEmptyMovieClip("img"+i,i);
setProperty("img"+i, _x, 102);
setProperty("img"+i, _y, 137);
loadMovie(i+".jpg", "img"+i);
onClipEvent(load) {
button.duplicateMovieClip("btn"+i, 150+i);
setProperty("btn"+i, _x, 797);
setProperty("btn"+i, _y, i*12+138);
}
}
jkoxvold webforumsuser@macromedia.com Guest
-
preloading an flv
Does anyone have any suggestions for creating a preloader for my flv movie (streaming an external flv into the flv playback component(Flash 8). I... -
Preloading xml files
i've made a photo gallery in mx2004 pro and everything works as it supposed to do. i've use the xmlconnector, imageloader and the combo box. If i... -
preloading in segments
How can I preload a flashwebsite in segments? I'm building a website with 9 'rooms'. The background and the main navigation are the same in all the... -
Preloading
I have two questions: 1) Does anyone know which one is the best methode of preloading the movie......i got a cd from a university of Vanderbilt,... -
Preloading swf in projector
Ok, I have a projector file that loads an external swf with loadMovie. The swf is fairly large (20 megs) so it takes a few seconds to load in, in... -
jkoxvold webforumsuser@macromedia.com #2
Re: Help with preloading jpg!!!
there's more!
i replaced a couple of bits in here based on some nuggets i picked up elsewhere on the site - but now i'm getting a whole new error:
**Error** Scene=works, layer=actions, frame=1:Line 27: Clip events are permitted only for movie clip instances
onClipEvent(data){
Any ideas on how to fix this? Any preference on which way to go from here?
thanks much.
i = 1;
for (i; i<=nr; i++){
createEmptyMovieClip("img"+i,i);
setProperty("img"+i, _x, 102);
setProperty("img"+i, _y, 137);
"img"+i.loadMovie(i+".jpg");
onClipEvent(data){
if (this.getBytesLoaded()>=this.getBytesTotal()) {
button.duplicateMovieClip("btn"+i, 150+i);
setProperty("btn"+i, _x, 797);
setProperty("btn"+i, _y, i*12+138);
}
}
}
jkoxvold webforumsuser@macromedia.com Guest
-
kglad webforumsuser@macromedia.com #3
Re: Help with preloading jpg!!!
your code should look like this:
for (i=1; i<=nr; i++) {
rclip = createEmptyMovieClip("img"+i, i);
rclip._x = 102;
rclip._y = 137;
rclip.loadMovie(i+".jpg");
rclip.onData = function() {
if (this.getBytesLoaded()>=this.getBytesTotal()) {
button.duplicateMovieClip("btn"+i, 150+i);
setProperty("btn"+i, _x, 797);
setProperty("btn"+i, _y, i*12+138);
}
};
}
but this won't work because onData and onLoad events only work for movieclips that are instantiated AND have a movieclip symbol in the library. you need to use preload-type code. for example:
preloadA = new Array();
for (ivar=1; ivar<=nr; ivar++) {
rclip = createEmptyMovieClip("img"+ivar, ivar);
rclip._x = 102;
rclip._y = 137;
rclip.loadMovie(ivar+".jpg");
rclip.jvar = ivar;
preloadA[ivar] = setInterval(preloadF, 100, rclip, rclip.jvar);
}
function preloadF(mc, ind) {
if (mc.getBytesLoaded>0 && mc.getBytesLoaded()>=mc.getBytesTotal()) {
clearInterval(preloadA[ind]);
button.duplicateMovieClip("btn"+i, 150+ind);
setProperty("btn"+ind, _x, 797);
setProperty("btn"+ind, _y, ind*12+138);
}
}
kglad webforumsuser@macromedia.com Guest
-
jkoxvold webforumsuser@macromedia.com #4
Re: Help with preloading jpg!!!
thanks kglad for posting that, your help is much appreciated.
but... greh, wincing as i'm typing this! i dropped in the second block of code replacing my old code. it continues to load the images successfully, but the buttons aren't showing up at all now (previously they all appeared at once).
i've been busting through the code trying to get my head round it (scripting is still rather new to me, as i'm sure you can tell). where i'm having trouble mostly is in the second part where it builds the preload, attached below. i can't quite figure out where mc and ind come into play so i'm thinking i maybe need to swap out those for img+ivar and ivar. or something.
any more tips you could give me would be met with rapturous applause.
function preloadF(mc, ind) {
if (mc.getBytesLoaded>0 && mc.getBytesLoaded()>=mc.getBytesTotal()) {
clearInterval(preloadA[ind]);
button.duplicateMovieClip("btn"+ind, 150+ind);
setProperty("btn"+ind, _x, 797);
setProperty("btn"+ind, _y, ind*12+138);
trace("button generated");
}
}
jkoxvold webforumsuser@macromedia.com Guest
-
kglad webforumsuser@macromedia.com #5
Re: Help with preloading jpg!!!
mc and ind are passed to preloadF() by setInterval(). the last two parameters in setInterval() - rclip and rclip.jvar - correspond to mc and ind, resp.
for your buttons to be duplicated you need a movieclip on the same timeline as that code and it needs to have an instance name of button which, btw, is not a good name choice.
kglad webforumsuser@macromedia.com Guest
-
jkoxvold webforumsuser@macromedia.com #6
Re: Help with preloading jpg!!!
the problem doesn't seem to be in the instance naming (which i've also changed to master_btn as per your advice) - if I strip out all the interval code it creates 36 buttons, positioned correctly. but maybe I've got something else wrong.
I know you respond to a lot of posts here, but if you could walk me through it, I would be very, very grateful. my email address is jason at betaplanet dot org. once I get it all right I'm more than happy to post the source files on my site for others to pilfer.
jkoxvold webforumsuser@macromedia.com Guest
-
kglad webforumsuser@macromedia.com #7
Re: Help with preloading jpg!!!
there's no code to make buttons without the setInterval statement. are you sure you tried the following code attached to a frame?
preloadA = new Array();
for (ivar=1; ivar<=nr; ivar++) {
rclip = createEmptyMovieClip("img"+ivar, ivar);
rclip._x = 102;
rclip._y = 137;
rclip.loadMovie(ivar+".jpg");
rclip.jvar = ivar;
preloadA[ivar] = setInterval(preloadF, 100, rclip, rclip.jvar);
}
function preloadF(mc, ind) {
if (mc.getBytesLoaded>0 && mc.getBytesLoaded()>=mc.getBytesTotal()) {
clearInterval(preloadA[ind]);
button.duplicateMovieClip("btn"+ind, 150+ind);
setProperty("btn"+ind, _x, 797);
setProperty("btn"+ind, _y, ind*12+138);
}
}
kglad webforumsuser@macromedia.com Guest
-
jkoxvold webforumsuser@macromedia.com #8
Re: Help with preloading jpg!!!
oh crikey.
i may not be the sharpest scripter in the box, but please. yes, i've tried your code attached to a frame. have you? which is why i asked you contact me directly; while you're guessing what my file looks like, this isn't going anywhere.
what I meant in terms of the buttons and the setinterval statement was more about getting rid of the preloadF code that seems to be the problem (see below) and the buttons appear as they should - but all at the same time, which is not the aim.
i'm sure if you took a quick peek at my file we'd find the problem in seconds. i also want to offer you a gesture of thanks, but privately. whaddya say?
preloadA = new Array();
for (ivar=1; ivar<=nr; ivar++) {
rclip = createEmptyMovieClip("img"+ivar, ivar);
rclip._x = 102;
rclip._y = 137;
rclip.loadMovie(ivar+".jpg");
rclip.jvar = ivar;
masterbtn.duplicateMovieClip("btn"+ivar, 150+ivar);
setProperty("btn"+ivar, _x, 797);
setProperty("btn"+ivar, _y, ivar*12+138);
}
jkoxvold webforumsuser@macromedia.com Guest



Reply With Quote

