Guys, I think we need to focus here. This thread is getting a little heated for no reason, and we're not getting anywhere.
This problem needs to be addressed - not just for myself, but for the other coders out there who go through the effort of learning AS3 and are then put off due to problems like this one.
I'm so used to AS3's power and flexibility now that I simply cannot go back to the old ways. I'm sure I speak for a lot of people out there.
Everybody has been helpful so far and some good stuff has been posted. But we're still nowhere near solving this issue. I know I ranted about Adobe earlier but out of honesty don't believe that a company as well respected as Adobe would release a development environment, encourage you to use the new language, and then cripple the most fundamental element of a flash movie, which is a pre loader that actually shows the progress before everything has loaded.
As mentioned before my game is for web delivery to multiple sites, so separate assets and a separate pre loader is not ideal (considering the fact that some sites only allow you to upload 1 single swf).
There's got to be a simple solution out there for this - I just know it.
Ok, the article on the BIT-101 Blog describes the situation for Flex, where the movie has no timeline. Basically what it describes is to introduce frames, which usually are not allowed in Sprite-based objects. If you use Flash you don't have that problem, because you can create movies with frames. The main problem is export in frame1, which can be unchecked, although in AS2 it gave problems with components sometimes.
- The right of the People to create Flash movies shall not be infringed. -
Don't get me wrong, I can see that the way I learned it was a simplification and pretty much just incorrect. It's just unfortunate that I had to get that info from the links posted instead of the person telling me I was wrong.
-but, to help move this back to the topic:
I've tried switching off "Export on first frame" for every linked asset and set the document's settings to "Export classes in frame 2" but the whole thing goes bananas and I just get a boat load of compile errors (<--- anyone know why this happens?!!)
The link explaining it in Flex doesn't help because that's in flex. We need to figure out why those errors are there.
So basically,
If you use Flash you don't have that problem,
except that he does have a problem.
Can somebody put together something in Flash that preloads like this for us so we can at least see if there's an obvious difference between it and what he's doing?
If we don't see the fla or a sample fla demonstrating the errors we can discuss for weeks without any further progress. The solution for Flex is not necessarily Flex specific. It is specific for Sprites. It, however, shows what you need: a timeline with two frames.
- The right of the People to create Flash movies shall not be infringed. -
Are you testing the preloader within Flash (Test Movie:CTRL+Enter) with an MP3 file on the local drive?
Something like:
Code:
var sound:Sound = new Sound();
var request:URLRequest = new URLRequest("my_song.mp3");
...
sound.load(request);
Because if you do, the preloader will not work properly, no matter if you try to simulate the download with the "Simulate Download" function of the debugger. The preloader will only appear (briefly) when the MP3 has totally been loaded, leaving you puzzled and wondering what you did wrong.
If you try to test the same code -- and I'm assuming the preloader itself is working properly -- with an MP3 from the internet it should work as expected.
Thanks for all the replies and all the offers for help.
I think you're right. I need to post an FLA so people can see whats
going on.
But just before I do, theres one more thing I want to try.
I was looking at cancerinform's tutorials regarding the AS3 preloaders.
A friend of mine was looking at these and said it might be a possible
solution to my problem (hes a computer science type guy). I want to
give this a go and see what happens.
I've tried to follow the preloader tutorial but had little success and I'm
not sure how to go about using the classes (I tried them before but had
little success).
Cancerinform, can you please help me here? Perhaps a quick explanation on how to use the classes or perhaps if you could post a small FLA which uses them, would be awesome! Thanks.
I've been following this thread with interest, as I've been struggling with the same thing - getting a preloader working with a game I've written in AS3, (with sounds), which keeps everything in one .swf file, with no need to load any external files. The question was asked above, has anyone actually managed this - well after quite a lot of struggling - yes, I think I have. It uses the method of putting the preloader onto frame one with some actionscript (which I found around here somewhere, forgive me as I can't remember who it was written by - perhaps it was cancerinform). The actionscript compares the bytesLoaded with the bytesTotal for the stage. You then drag everything from the library onto frame two, and then on frame three, you get rid of it all and have your main program script, which creates objects from the library dynamically. I will try and get a .fla posted tomorrow to show an example.
Uh... You can do it the same way it was done in AS2.0...
Frame 1:
Code:
var p:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal * 100;
trace (p);
this.percent.text = p.toString();;
if (p > 99) {
gotoAndStop(4);
}
Frame 2:
Code:
gotoAndPlay (1);
Place all your exported assets on frame 3, dont export them on frame 1.
Last edited by 691175002; 02-03-2008 at 03:48 PM.
The greatest pleasure in life is doing what people say you cannot do.
- Walter Bagehot The height of cleverness is to be able to conceal it.
- Francois de La Rochefoucauld
Here is a link to the .fla which shows an example of my preloader. As I mentioned, it's self contained, and seems to work fine with sounds as well. Note that I created a separate movie clip to contain the sounds (with one sound on each layer), and dragged this movie clip, as well as all other linked assets, onto the stage in frame 2. All linked assets have the 'export in frame 1' box unchecked. Any questions, just ask.
I've knocked up a quick fla demonstrating the problem I'm having.
I can't post the actual game I'm working on because its far too big.
This test FLA contains one single embedded asset which is linked as a class. Its added to the stage as an instance using actionscript (which is how I do pretty much everything).
I know theres a way to get round this by manually placing sounds and images on an unused frame and unchecking "export on 1st frame" but if you saw the size of my game you would realise thats almost impossible. I need to get round this problem without placing things on stage manually, but if the worst comes to the worst then I may have to employ that method.
Theres a preloader in this FLA but if you simulate a download and set the speed to something low, you will see that nothing happens until the whole thing has loaded.
OK guys, check out the FLA and if you can help me out with this problem then I'll be very grateful! Thanks!
PS: Cancerinform - I tried using your preloader class but it gave me the same result. I may have done it wrong though - I'm not sure.
I see the problem. This is very similar to the problem in former flash versions with components. The only thing you can do is load into an empty movie. I made an example and also change the preloader script. This is the only way you can do it if you do not place every item on the timeline.
Thanks for that! I've managed to get a pre-loader working which loads an external swf file, but I've still had no luck with the integrated single-file version. I even tried importing the main swf into the library of the preloader and it didn't work. Theres got to be a solution for this out there somewhere. I just know it.
But anyway, for now I'm having to place things on stage manually for all my small games and for my main project I'm just gonna have to use an external preloader and manually email a zip file to the webmaster of any flash games site who normally only allow you to upload a single swf.
Heres me, hoping there is someone out there reading this, who can help solve this issue!
I was having the same problem as you. When attempting to preload all frames after the first using loaderInfo and unchecking "export in first frame", I would get compiler errors, specifically:
Code:
ReferenceError: Error #1065: Variable TeamClip is not defined.
at AboutContent/TeamDown()
If this is the problem you are having, the solution is simple but tedious. As some above posters mentioned, you need to copy all the library items that are having the aforementioned errors to the frame where you use them. Since most of my library items are being instantiated via ActionScript, this is not done automatically.
My project is two frames: one for the preloader, and one for the main content. I created a second layer for my scene called "preloaded items" and pasted all the items (mainly movieclips) from my library onto this layer in frame 2. Then I made it invisible. Voila, no more errors.
I've done it the way entechie suggested and the way I've always done it in AS2 but to be honest, it's ugly and I agree that Adobe should have given us a more elegant way in AS3 ... ha well, the rest of AS3 is pretty cool at least.
It shows a 'spinning circles' animation with the % loaded underneath.
Problem is it's a standalone preloader and uses the loader function to load in the main SWF.
The main SWF file contains links to websites, which work fine if I don't use the preloader, but just don't do anything if I do use the preloader, any ideas guys ?
I think the problem maybe in my "completed" handler below:
function completed(e:Event):void
{
ring.visible=false;
textbox.visible=false;
addChild(loader);
}
It shows a 'spinning circles' animation with the % loaded underneath.
Problem is it's a standalone preloader and uses the loader function to load in the main SWF.
The main SWF file contains links to websites, which work fine if I don't use the preloader, but just don't do anything if I do use the preloader, any ideas guys ?
I think the problem maybe in my "completed" handler below:
function completed(e:Event):void
{
ring.visible=false;
textbox.visible=false;
addChild(loader);
}
Ignore that that, I was being a plank, I was loading the swf from a subdomain of the domain it was in, cross domain error!