Creating A Loading Screen From A Swf

8 posts

Flag Post

I was looking online for a tutorial on how to create a loading screen. However I have only seen examples of creating loading screens where a loading bar is put on frame 1 and everything else in the game happens on frame 2.

Somewhere I also came across someone saying that you can load a swf from another swf and avoid the need to have a second frame, but I could not find code or an example of how this is done.

Does anyone have an example of creating a loading screen/bar in this way or in some way that does not require code on the timeline or more than 1 frame?

 
Flag Post

There has to be at least a thousand tutorials for this on the web. Check the help files under flash.display.Loader. Here’s some basic code (written on my phone, so watch for errors):

var l:Loader = new Loader()
addChild(l)
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progress)
l.load(new URLRequest("my.swf"))
function progress(e:ProgressEvent):void {
    trace(e.bytesLoaded / e.bytesTotal)
}
 
Flag Post

Ok so I created a new .fla and put that in the timeline (although I would is possibile like to avoid timeline code) and got an error when trying to reference the stage in my ‘real’ swf file.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Main()[C:\Users\Evan\Desktop\Tile Rouge Like\Main.as:563]

And that line is


stage.addEventListener(MouseEvent.RIGHT_CLICK, function(e:Event){});

Any ideas on whats causing that error or how to not have timeline code?

 
Flag Post

It’s telling you that stage is null. Probably, the calling DisplayObject is not on the display list (ie not eventually a child of stage).

Or, less likely, MouseEvent is null.

 
Flag Post

I don’t quite understand what you’re saying…

 
Flag Post
Originally posted by evan999333:

Ok so I created a new .fla and put that in the timeline (although I would is possibile like to avoid timeline code) and got an error when trying to reference the stage in my ‘real’ swf file.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Main()[C:\Users\Evan\Desktop\Tile Rouge Like\Main.as:563]

And that line is


stage.addEventListener(MouseEvent.RIGHT_CLICK, function(e:Event){});

Any ideas on whats causing that error or how to not have timeline code?

That’s because stage is null. Add an Event.ADDED_TO_STAGE event listener and put the code on the event handler

 
Flag Post
Originally posted by evan999333:

I don’t quite understand what you’re saying…

He told you exactly what went wrong. The DisplayObject you are calling from is not on the display list.

 
Flag Post

Thank you BigJM and SumGato (for explaining how use fix what BigJM pointed out.) Works perfectly.