Hi!
it should work even without writing stop() in the loaded swf in this way:
Code:function fileLoaded(event:Event):void { var movie:*=loader.content; var clip:MovieClip=movie; clip.gotoAndStop(1); addChild(clip); clip.play(); }
Hi guys,
I've tried creating a preloader for an external swf that I've made.
So far I've used the code:
ar req: URLRequest = new URLRequest("Whole_movie.swf");
var loader:Loader = new Loader();
function fileLoaded(event:Event):void
{
addChild(loader);
}
function preload(event:ProgressEvent):void
{
var percent:Number = Math.round(event.bytesLoaded / event.bytesTotal * 100);
preload_txt.text = String(percent) + "%";
}
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, fileLoaded);
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, preload);
loader.load(req);
However, the video starts playing in the background before it is fully loaded so when the view actually starts watching it, it is already a significant amount of the way through. I have been advised to put a stop(); at the beginning of the swf, which I have done and then overide this with MovieClip(loader.content).play(); in the method 'fileLoaded' just before the addChild(loader);
I know virtually nothing about Actionscript 3 though and so I don't know where to insert this. I've tried in numerous places and keep getting the following output: "TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@2aa33481 to flash.display.MovieClip.
at Preloader_fla::MainTimeline/fileLoaded()"
Can someone copy and paste the existing code and show me exactly where to insert MovieClip(loader.content).play(); please?
Thanks in advance!
Oli
Hi!
it should work even without writing stop() in the loaded swf in this way:
Code:function fileLoaded(event:Event):void { var movie:*=loader.content; var clip:MovieClip=movie; clip.gotoAndStop(1); addChild(clip); clip.play(); }
Hi,
Thanks for your response. Unfortunately it didn't work, it just outputted this message:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@28506781 to flash.display.MovieClip.
at Preloader_fla::MainTimeline/fileLoaded()
A guy in another forum said this was because I was trying to load an Actionscript 2 swf into an Actionscript 3 file. He also said it was really hard to get around this and probably more trouble than it's worth.
Any ideas on how to do this simply?
Cheers!
The reason for your problem is that your movie starts playing already when it is loading.
2 things you need to do.
1. convert your loader content into a movieclip//MovieClip(loader.content)
2. then make it start from frame 1 when loading is completed //gotoAndPlay(1)
just add the new line to your fileLoaded function:
function fileLoaded(event:Event):void
{
addChild(loader);
MovieClip(loader.content).gotoAndPlay(1);//add this new line
}
I had the same problem a few days ago, that's how I solved it. Hope it works for you too.
Bookmarks