PDA

View Full Version : preloader causing typeError #1009



ACKtion
July 10th, 2009, 06:07 PM
I have been coding my flash movie/website and everything was working fine until I added a preloader on frame one, moved frame "home" over one frame to frame2. PaulJamesWilliams is the name of the file that I am editing. what do I do?


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PaulJamesWilliams_fla::MainTimeline/frame2()
at flash.display::MovieClip/nextFrame()
at PaulJamesWilliams_fla::MainTimeline/updatePreloader()

I cam post whatever code I need to....

:ear:

IQAndreas
July 10th, 2009, 07:39 PM
This is REALLY common.

If you use a preloader, in the main code of "PaulJamesWilliams", you need to start your code like this.

If you code directly on the timeline:

stop();

this.addEventListener(Event.ADDED_TO_STAGE, start);
function start(ev:Event):void
{
//Put ALL of your code for frame 1 inside of here
//You can even put a play() command if you want it to go ahead on to frame 2.
}

If you use a document class, I can give you that code as well.

The best thing to do is to use another SWF to do all the preloading. If you do, it will save you a lot of hassle, and is quite simple to create.

Here is a site which explains it quite well:
http://www.zedia.net/2008/the-right-way-to-do-a-preloader-in-as3/



var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent .PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLET E, done);
l.load(new URLRequest("content.swf"));

function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
}

function done(e:Event):void
{
removeChild(percent); // was removeChildAt(0) but it make more sense this way
percent = null;
addChild(l);
}