|
-
[F8] Triggering an event when an image loads...
Hello there.
I've had a good look around the forum - and Flash Help has once again not been very helpful.
I'm just trying to have a function triggered when a certain amount of images have loaded. I've tried so many variations (including copying code from here) but it's not working!
Here's what I've got...(excluding the image-loading code).
var mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(){
imagesLoaded ++;
trace(imagesLoaded);
if (imagesLoaded == 4) {
images.title.start_btn._visible = true;
loader._visible = false;
};
};
mcl.addListener(mclListener);
Is there anything wrong with that? When 4 images have loaded, it's supposed to make the 'start' button visible, but no go so far.
I've tried using 'onLoadComplete' instead, but from some comments on-line it sounds like that might behave a bit unpredictably.
If anyone can help me out, that'd be great.
-
What are you getting in the output of your trace()? Maybe also add a trace inside the if (imagesLoaded == 4) {} which just says something like trace("entered if statement");
I'm not sure if it matters but I don't think there should be ;'s after the }'s - you have two of them.
-
Hey there.
I'm not getting anything from the 'trace' because the onLoadInit never gets triggered. Likewise when I use onLoadComplete.
I just tried taking out the ;'s but that made no difference.
There must be something simple about the syntax that I'm just not getting... Is the move clip listener set up right?
Any help appreciated.
-
I'm probably not the best guy to try help you with this (anyone else wanna jump in here?), but I'm gonna give it a shot anyways.
Could you maybe post all the code, including the image loading code? Because so far as I can see that code looks good- so long as the image loading code is done right (calling loadClip and all that). Are you using the same MovieClipLoader to load all the images? Are you loading them into movie clips defined in code or on the stage?
-
Hmm... perhaps that's what I'm doing wrong...
I'm loading the images into a container which is pre-placed on the stage.
Here's the full code...
images.title.start_btn._visible = false; // makes start button invisible
imagesLoaded = 0;
// Create listener object:
var mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(){
imagesLoaded ++;
trace(imagesLoaded);
if (imagesLoaded == 4) {
images.title.start_btn._visible = true;
loader._visible = false;
}
}
mcl.addListener(mclListener);
// Load images
images.title.image.loadMovie("images/tvimage.png");
images.panel1.loadMovie("images/Panel01_02.png");
images.panel2.loadMovie("images/Panel02_02.png");
images.panel3.loadMovie("images/Panel03_02.png");
images.panel4.loadMovie("images/Panel04_02.png");
images.panel5.loadMovie("images/Panel05_02.png");
images.panel6.loadMovie("images/Panel06_02.png");
images.end.end.image.loadMovie("images/tvimage.png");
...spot anything wrong with that?
-
mcl:MovieClipLoader is not being used to load the images, so it never fires any events (calls any functions). You need to use mcl.loadClip("images/tvimage.png", images.title.image); etc
Edit: Also, you may need to use a different MovieClipLoader for each image. You should be able to use only one mclListener though. Try it first with just the one MovieClipLoader, but if you have trouble then you're going to need to use a unique loader for each image.
Having the container pre-placed on the stage is not a problem.
Last edited by daneduplooy; 08-05-2008 at 08:07 AM.
-
Awesome! That's done the trick. I'm guessing that seemed painfully obvious to you, but I didn't know how it was supposed to work. Thanks a lot!
-
Lol Not painful at all- glad I could help!
-
Senior Member
nevermind. i c u got. Great!
If you don't think you're going to like the answer, then don't ask the question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|