Copy link to clipboard
Copied
First things first, please don't recommend I change to AS3 for this. It's far too late for that and not my project to be dictating.
So I'm loading some external swfs in with the loadMovie command, in the normal manner with a button:
on (release) {
loadMovie("swfs/example-1.swf", _root.container);
}
But what I need, is to wedge a preloader in there somehow. As the swfs are around 1mb each.
I'm already using the following as a preloader for the main file, so an adaptation of it would be very welcome so I can co-ordinate the graphics:
var amountLoaded:Number = _root.getBytesLoaded() / _root.getBytesTotal();
preloaderText.text = Math.round(amountLoaded * 100) + "%";
---
if (_root.getBytesLoaded() == _root.getBytesTotal())
{ gotoAndPlay(3); }
else
{ gotoAndPlay(1); }
So would there be a way to wedge my preloader into that first lot of code?
you're using a movieclip button, not a true button. use:
...
on (release) {
_parent.preloadI=setInterval(_parent.preloadF,100,_root.container)
loadMovie("swfs/example-1.swf", _root.container);
}function preloadF(container:MovieClip)
{
var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
preloaderText.text = Math.round(amountL*100)+"%";
if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
{
clearInterval(prelo
Copy link to clipboard
Copied
is that a true button or a movieclip button? (and, you really shouldn't attach code to objects).
Copy link to clipboard
Copied
Yep, it's a true button
Copy link to clipboard
Copied
// attached to the frame that contains your button
on (release) {
preloadI=setInterval(preloadF,100,_root.container) loadMovie("swfs/example-1.swf", _root.container);
}
preloaderText.text = Math.round(amountLoaded * 100) + "%";
if (mc.getBytesLoaded() == mc.getBytesTotal() & mc.getBytesTotal()>0){
clearInterval(preloadI);
// do whatever
}
}
Copy link to clipboard
Copied
Unless you are publishing to a very low target player, you might want to look at using the MovieClipLoader class instead of loadMovie and an old-school preloader.
The MCL class gives you some nice events such as onLoadError that you won't get with the hand-made approach.
Copy link to clipboard
Copied
I realise this will be terrible feedback, but it didn't work
Here's what I put in the button:
on (release) {
preloadI=setInterval(preloadF,100,_root.container)
loadMovie("swfs/example-1.swf", _root.container);
}
And here's what I put in the containing frame:
function preloadF(container:MovieClip)
{
var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
preloaderText.text = Math.round(amountLoaded * 100) + "%";
if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
{
clearInterval(preloadI);
}
}
So I have no idea what went wrong really.
Copy link to clipboard
Copied
copy and paste the output panel result:
on (release) {
trace("btn "+this);
preloadI=setInterval(preloadF,100,_root.container)
loadMovie("swfs/example-1.swf", _root.container);
}trace("preloadF "+this);
function preloadF(container:MovieClip)
{
var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
preloaderText.text = Math.round(amountLoaded * 100) + "%";trace(preloaderText+" "+amountLoaded);
if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
{
clearInterval(preloadI);
}
}So I have no idea what went wrong really.
Copy link to clipboard
Copied
Output from that:
preloadF _level0
btn _level0.instance3
Copy link to clipboard
Copied
you're using a movieclip button, not a true button. use:
on (release) {
_parent.preloadI=setInterval(_parent.preloadF,100,_root.container)
loadMovie("swfs/example-1.swf", _root.container);
}function preloadF(container:MovieClip)
{
var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
preloaderText.text = Math.round(amountL*100)+"%";
if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
{
clearInterval(preloadI);
}
}
Copy link to clipboard
Copied
ah, thankyou. That seems to work just fine
I assumed because even though my button is inside a movie clip, as it is button, it was still considered a true button.
Now there is another problem, I know its not part of the preloader business, but its still relevant:
The swf I load in with loadMovie appears before it's completely loaded. How do i stop this?
Copy link to clipboard
Copied
assign the _alpha of your target movieclip to 0 until loading is complete. then direct its timeline to frame 1 and assign its _alpha to 100.
Copy link to clipboard
Copied
ah thanks. I was trying _visible and it wouldn't quite work for me.
Anyway. All done.
cheers
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now