Hi
I found a cool preloader tutorial with a free preloader which I added onto my flash project. I did it by creating a new scene before my project scene, and adding the preloader to it.
The pre loader works fine, and my project all worked fine before I put the preloader on, but now after the preloader finishes, my site's buttons won't work and in Flash CS4 there is a compiler error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at website_fla::MainTimeline/frame2()
Take the preloader scene away, and my site works fine again.
Any idea what I need to do to make them work together?
Cheers
Shaun
Sorry - here it is:
01.importflash.events.ProgressEvent;02.functionupdate(e:ProgressEvent):void03.{04.varpercent:Number=Math.floor( (e.bytesLoaded*100)/e.bytesTotal );05.if(preloaderMC isMovieClip){06.preloaderMC.gotoAndStop(percent);07.}08.if(percent == 100){09.play();10.}11.}12.loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);13.// Extra test for IE14.varpercent:Number=Math.floor( (this.loaderInfo.bytesLoaded*100)/this.loaderInfo.bytesTotal );15.if(percent == 100){16.nextFrame();17.}18.stop();http://www.flashmagazine.com/tutorials/detail/how_to_make_a_custom_as3_preloader/
and here's the page it came from:
Cheers
Here's the new erroe:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at website_fla::MainTimeline/frame2()[website_fla.MainTimeline::frame2:1 8]
I don't understand, because there is nothing on Frame 2 in either the preloader scene, nor the main movie scene.
When I test each individual scene, they work fine. But testing the movie brings that error, and my main movie scene doesn't work properly (it comes up, but no functionality).
Does that info trigger any thoughts?
Cheers
I still don't understand it.
I have two scenes - Preloader and Scene 1 - neither have any script on frame two.
The preloader script is:
import flash.events.ProgressEvent;
function update(e:ProgressEvent):void
{
var percent:Number = Math.floor( (e.bytesLoaded*100)/e.bytesTotal );
if(preloaderMC is MovieClip){
preloaderMC.gotoAndStop(percent);
}
if(percent == 100){
play();
}
}
loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);
// Extra test for IE
var percent:Number = Math.floor( (this.loaderInfo.bytesLoaded*100)/this.loaderInfo.bytesTotal );
if(percent == 100){
nextFrame();
}
LINE18: stop();
and scene1's script is:
stop();
function colorNav(event:MouseEvent):void{
gotoAndPlay(event.target.name);
}
function getGilbert(event:MouseEvent):void {
navigateToURL(new URLRequest("mailto:info@gilbert.net.au"));
}
LINE18: karaoke.addEventListener(MouseEvent.CLICK,colorNav);
trivia.addEventListener(MouseEvent.CLICK,colorNav);
gilbert.addEventListener(MouseEvent.CLICK,colorNav);
email.addEventListener(MouseEvent.CLICK, getGilbert);
I've highlighted both line 18s. Is there another main overall timeline that I'm not aware of? How do I get to that?
Cheers for your help on this.
Shaun
OK, I'm trying to figure it out, but I thought I'd give you an update in case I'm missing something obvious.
I tried testing just Scene 1 - it works (we already know that).
As an experiment, I then selected all the layer 1 frames in the scene, and dragged them to frame 2, so frame one is blank on all layers. Now when I test the scene, the movie looks normal, but the menu buttons won't work and I get the error again.
So that tells me that the 'Preloader' scene is fine and isn't causing the problem, it's Flash not liking 'Scene 1' not starting from frame 1.
Does this clue help?
no, i didn't think that added any info.
here this may help you help yourself. scenes don't exist when you publish/test your swf. flash arranges the timeline of each scene from the last frame of the previous scene followed immediately by the first frame of the next scene.
so, that's why we know the error is in your 2nd scene's frame 1. the first scene only has 1 frame so the next frame will be the first frame of the 2nd scene. if you post the line of code that matches the number in the error message, we should be able to pinpoint the object reference causing the problem.
OK - here's a screenshot of the code from frame 2 of the movie - it's just three buttons jumping to different parts of the scene, plus an email button:
if I delete line 18, then line 19 creates an error, and so on.
It's strange, because when I test just the scene, it plays fine - the buttons work.
And here's the code from the preloader scene:
01.import flash.events.ProgressEvent;
02.function update(e:ProgressEvent):void
03.{
04. var percent:Number = Math.floor( (e.bytesLoaded*100)/e.bytesTotal );
05. if(preloaderMC is MovieClip){
06. preloaderMC.gotoAndStop(percent);
07. }
08. if(percent == 100){
09. play();
10. }
11.}
12.loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);
13.// Extra test for IE
14.var percent:Number = Math.floor( (this.loaderInfo.bytesLoaded*100)/this.loaderInfo.bytesTotal );
15.if(percent == 100){
16. nextFrame();
17.}
18.stop();
Thanks for taking a look kglad
Thanks for taking a look kglad, but she still isn't working.
When I click the buttons, still nothing happens - it's not jumping to the appropriate part of scene 1. The rollover graphic happens, but that never stopped working anyway.
Also, there are now double instances of the objects in the preloader. If I try deleting either instance of preloaderMC, the preloader doesn't work. I'm not sure what's going on with it.
Cheers
OK - she's working apart from that now when you hit the 'Solo Entertainer' button, it displays the 'Trivia' page instead of the 'Gilbert' page, and generates this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at website_fla::MainTimeline/__setProp___id1__Scene1_GILBERT_71()[websit e_fla.MainTimeline::__setProp___id1__Scene1_GILBERT_71:7]
at website_fla::MainTimeline/frame72()[website_fla.MainTimeline::frame72 :3]
There is definitely no code on line 7 or 3 of frame 71 and 72, so it's very strange.
Just to make sure I entered it correctly, should the code look like?:
11. stage.invalidate();
12. this.addEventListener(Event.RENDER,frame2RenderF);
LOL - it bizzarre - it works when I test just the scene, but when testing the whole movie, the SOLO ENTERTAINER button definitely brings up the trivia page, not Gilbert.
No matter - thanks for giving it a go kglad - I appreciate the time and effort you've put in here.
What's your email addy? I want to Paypal you some money for your time. They should have it set up here on the forums that members can have donations made to them for their time.
Cheers
when i run it the gilbert buttons opens the gilbert page (complete with tainted love!). and then if i click anything else the video keeps playing (and if i click gilbert again i hear tainted love playing over tainted love in an awful cacophony that all flashers know too well).
are you sure it's not working for you? is the website.fla dated 6/10 at 7:47 am?
Haha - gotta love the 80's
I deleted the fla file and re-downloaded it, unzipped it (7:47am like you said) and opened it in Flash, and yep, still the same problem. And it spits out this compiler error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at website_fla::MainTimeline/__setProp___id1__Scene1_GILBERT_71()[websit e_fla.MainTimeline::__setProp___id1__Scene1_GILBERT_71:7]
at website_fla::MainTimeline/frame72()[website_fla.MainTimeline::frame72 :3]
Yeah - fixing the video so it stops when leaving the page is the next step after I fix this first problem.
Here's the .swf it's generating
i see that problem on your site. but not on mine: http://www.kglad.com/Files/website.html
i zipped the fla, html and swf and reupped: http://www.kglad.com/Files/website.zip
Wow - still the same prob
I thought it might have been Firefox using the same file in cache, so I emptied it, and even tried loading it using IE, but still the same prob.
But yes - when I click on the file via your website, it works fine.
I'm going to try loading it onto another computer, just to see if something funny is going on with mine.
Nope - it's still the same problem on the other computer too. I'm going to go do some gardening and have a think about this.
The only thing I can think of is that the .swf that's in the zip file is somehow a cached version and not the updated version you have at www.kglad.com/files - but I really don't know how - I'm just guessing.
North America
Europe, Middle East and Africa
Asia Pacific