Copy link to clipboard
Copied
I am having a problem with this error when I am trying to use a function for a button. Everything works fine when I have it on frame 1, but when I add a preloader to frame 1 and put my content on frame two I recieve the #1009 error.
When I tested my code with just a simple function I still got the error. the code is below, Any help would be greatly appreciated!
****Code for Preloader(Frame1)*******
stop();
loaderInfo.addEventListener(ProgressEvent.PROGRESS, updatePreloader);
function updatePreloader(evtObj:ProgressEvent):void
{
var percent:Number = Math.floor((evtObj.bytesLoaded*100)/evtObj.bytesTotal);
preloader_txt.text=percent+"%";
if (percent>=100){
nextFrame();
}
}
****Code for Main Content (Frame 2)****
stop();
//Import the necessary files for all of the tweening
//--------------------------------------------------------
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
//---------------------------------
//Move all of the text off screen and set them invisible
//--------------------------------------------------------
featuresText_mc.alpha=0;
featuresText_mc.y=-500;
viewCottageText_mc.y=-500;
rateInfo_mc.alpha=0;
rateInfo_mc.y=-500;
viewCottageText_mc.alpha=0;
contactInfoText_mc.alpha=0;
//--------------------------------------------------------
viewCottage_btn.addEventListener(MouseEvent.CLICK, goCottage); function goCottage(evtObj:MouseEvent){
trace("test")
}
***Any Help would be greatly Appreciated***
is the code that causes the error message and the button in the same frame? if so, you have a typo.
Copy link to clipboard
Copied
click file/publish settings/flash and tick "permit debugging" and retest to pinpoint your error. the frame and line number that's causing the error will be displayed.
Copy link to clipboard
Copied
I have pinpointed the problem being the function that I am trying to call, but I still do not know why it is giving me a problem. I am assuming that something has not been initiated on stage from what I have read, but I have no clue how to fix it. Thanks.
viewCottage_btn.addEventListener(MouseEvent.CLICK, goCottage);
function goCottage(evtObj:MouseEvent)
{
trace("test")
}
Copy link to clipboard
Copied
a function won't give a null object reference error. the line above your function could be causing the error but it should be obvious which line is causing the error because the lines are numbered. which line is referenced in the error message and copy and paste the exact error message.
Copy link to clipboard
Copied
You're right,
viewCottage_btn.addEventListener(MouseEvent.CLICK, goCottage);
I found a similar post to mine(http://forums.adobe.com/message/2021469#2021469), you were able to help him, but unfortunately it was through file swapping so I could not reference the solution.
Do you think you can help me out?
Copy link to clipboard
Copied
if
viewCottage_btn.addEventListener(MouseEvent.CLICK, goCottage);
is the line referenced in the error message, viewCottage_btn doesn't exist when that error message occurs.
Copy link to clipboard
Copied
I am begining to understand. How can I go about making it exist when it is reference?
Copy link to clipboard
Copied
that depends how you create that instance.
if it's done on the timeline, then you should have that code attached to the first frame where that object first appears and never remove that object for as long as it's needed.
Copy link to clipboard
Copied
I have two scenes, each with one frame. The first scene calls the preloader code, and the second scene has the main content where the problem code is located. That is where the object first appears and that is where the code is but I am still getting an error.
I am confused because I do not reference it anywhere else. here is my code if that sheds any light on the subject.
Copy link to clipboard
Copied
use a trace() statement to confirm that the error occurs as the playhead enters the frame that contains your button for the first time. if so, you have a typo either in the code or the properties panel. use copy and paste to make sure they match.
Copy link to clipboard
Copied
I traced "fff" at the begining of scene two and it appeared before the error occurred. The instance name of the button and the reference I made are the same. but I am still getting errors for every button that I call.
fff
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at cottage_website_fla::MainTimeline/frame2()[cottage_website_fla.MainTimeline::frame2:10]
at flash.display::MovieClip/nextFrame()
at cottage_website_fla::MainTimeline/updatePreloader()[cottage_website_fla.MainTimeline::frame1:8]
Copy link to clipboard
Copied
is the code that causes the error message and the button in the same frame? if so, you have a typo.
Copy link to clipboard
Copied
Ok, I finally started a new flash file and used more than one frame. Everything seems to be working now. Thanks for your help!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hi kglad,
I recently suffered a similar problem and reading your advice here helped me get it working again. Just wanted to let you know your helping us all and we appriciate it
THANK YOU!!!
p.s. you're a genious
Copy link to clipboard
Copied
kglad, I believe you have helped billygoatkareoke out before with the exact same problem I am having now(http://forums.adobe.com/message/2021469#2021469). I think my buttons weren't instantiated when my test first played and the code executed.
You were able to solve his problem by looking at/and adjusting his code, unfortunately the code was not posted and the file link on the post is no more so I can not reference it. Is there any way you can help me out?
Thanks for your help so far.