• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Error #1009 Help!

Community Beginner ,
Oct 22, 2011 Oct 22, 2011

Copy link to clipboard

Copied

Dear All,

I hope you can help me with what is probably a very simple problem yet seems to affect most people! However, I've spent all day researching it and trying all sorts of codes to resolve the error!

I am in the process of building a new website using Flash CS5 and I am very new to whole scripting business (as3).  Having finished the main content of the website, I created an external preloader so it can load the main SWF file. However, when I debug or test the scene I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at Index_fla::MainTimeline/frame1()[Index_fla.MainTimeline::frame1:11]

After many hours, I find the publish settings, publish debugging which actually tells me what line/frame is causing the problem! If I go to my main file (labelled as Index.Fla) and look at Frame 1, Line 11 it indicates:

var buttonsArray:Array = [works_btn,about_btn,contact_btn];

... which sounds about right, considering when the preloader has finished the main flash file navigation buttons (work/about/contact) appear to not work quite right. They still function taking you to the right pages (or frames) but the mouse over, mouse click functions do not work.

Now I'm not really sure how to deal with this, because All the buttons (which are Movie clips) are located on Frame one and have the right instance names and PLUS when I debug the Index.Fla file, everything works as normal.

Should I assume there is something wrong with my preloader file?

Below is the script for the preloader and frame one fo the index file. Hope you can help me! Thanks!

PRELOADER:

var l:Loader = new Loader();

l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("Index.swf"));

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

function done(e:Event):void
{
   removeChildAt(0);
   removeChild(preloader)
   percent = null;
   addChild(l);

   l.contentLoaderInfo.removeEventListener( ProgressEvent.PROGRESS, loop);
   l.contentLoaderInfo.removeEventListener(Event.COMPLETE, done);

}

INDEX (MAIN FILE - FRAME ONE)


stop();

works_btn.addEventListener(MouseEvent.CLICK, navigationClicked);
about_btn.addEventListener(MouseEvent.CLICK, navigationClicked);
contact_btn.addEventListener(MouseEvent.CLICK, navigationClicked);

stage.frameRate = 30;
var buttonsArray:Array = [works_btn,about_btn,contact_btn];

   function setButtons():void
   { for (var i:int=0; i<buttonsArray.length; i++)
      {   buttonsArray.id = i;  
         buttonsArray.buttonMode = true;  
         buttonsArray.mouseChildren = false;  
         buttonsArray.mouseEnabled = true;  
         buttonsArray.addEventListener(MouseEvent.ROLL_OVER,playOver);  
         buttonsArray.addEventListener(MouseEvent.ROLL_OUT,playOut);  
         buttonsArray.addEventListener(MouseEvent.CLICK,doClick);  
      }
}

function playOver(event:MouseEvent):void
   {   event.currentTarget.gotoAndPlay("over");
   }
function playOut(event:MouseEvent):void
   {   event.currentTarget.gotoAndPlay("out");
   }

function doClick(event:MouseEvent):void{
  
   var currentBtn:int = event.currentTarget.id;  

   setSelectedBtn(currentBtn);
}

function setSelectedBtn(id:int):void{  
   for (var i:int=0; i< buttonsArray.length; i++) {  
      if (id == i) {  
         buttonsArray.gotoAndStop("down");  
         buttonsArray.buttonMode = false;  
         buttonsArray.mouseEnabled = false; 
         buttonsArray.removeEventListener(MouseEvent.ROLL_OVER,playOver);  
         buttonsArray.removeEventListener(MouseEvent.ROLL_OUT,playOut); 
         buttonsArray.removeEventListener(MouseEvent.CLICK,doClick);
         } else {  
            if(buttonsArray.currentLabel =="down"){
               buttonsArray.gotoAndPlay("out");  
               }  
               buttonsArray.buttonMode = true;  
               buttonsArray.mouseEnabled = true;  
               buttonsArray.addEventListener(MouseEvent.ROLL_OVER,playOver);  
               buttonsArray.addEventListener(MouseEvent.ROLL_OUT,playOut);  
               buttonsArray.addEventListener(MouseEvent.CLICK,doClick);
               }  
         }
      }
setButtons();

function navigationClicked(Event:MouseEvent):void
{
   var frmLabel:String = '';

    switch (Event.target)
   {
      case works_btn :
            frmLabel = "Portfolio_frm";
            break;
        case about_btn :
            frmLabel = "About_frm";
            break;
        case contact_btn :
            frmLabel = "Contact_frm";
            break;
   }
     
   if (currentFrame != frmGoto)
   {
     
      var frmPortfolio:Number = this.getFrame("Portfolio_frm");
           
      gotoAndPlay(frmGoto);
   }
}


function getFrame(frameName:String):Number
{
    var frame:Number = 1;

       for (var i = 0; i < currentLabels.length; i++)
    {
        if (currentLabels.name == frameName)
        {
            frame = currentLabels.frame;
            break;
        }
    }

    return frame;
}

TOPICS
ActionScript

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Oct 23, 2011 Oct 23, 2011

Ahh! Sorry. I did it again (purpose error code), and I think the problem was:

stage.frameRate = 30;

I took it out and the error #1009  notification disappeared! Not sure how or why it just did! Maybe it's unnecessary coding?

Thanks for your help though Kglad. Much appreciated

Votes

Translate

Translate
Community Expert ,
Oct 22, 2011 Oct 22, 2011

Copy link to clipboard

Copied

at least one of these objects does not exist:  works_btn,about_btn,contact_btn

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2011 Oct 22, 2011

Copy link to clipboard

Copied

Hi Kglad,

Thanks for your rapid response.

I've checked my index file and it appears the buttons are all there and reflect the instance names (works_btn,about_btn,contact_btn). When I debug the main Index file, all three buttons work fine.

What I should note is, that these "buttons" are made via Movie Clips, however, I have labeled them as _btn. Does the action script require the function :MovieClip after the btn, IE: works_btn:MovieClip?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2011 Oct 22, 2011

Copy link to clipboard

Copied

only if you're creating the reference with actionscript.  if you created the object in the ide and use whatever_btn in the properties panel, there's no problem.

to test your line number identification use:

trace(works_btn);

trace(about_btn);

trace(contact_btn);

var buttonsArray:Array = [works_btn,about_btn,contact_btn];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

Right, I placed your trace script into my file and this is the outcome:

[object works_btn_3]

[object about_btn_1]

[object contact_btn_2]

Slightly baffled why they come up this way!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

those are you object class names and that confirms all 3 objects are defined.  ie, you've mis-identified the problematic line number.

if you don't understand how indicates line numbers, remove those 3 trace statements and intentionally put a line of code that will trigger an error (hopefully above the current error so it triggers first).  check that line number and then move it until it's causing a line 10 error.  then you know the next line of code is your 1009 error causing line.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

Ok, so you're saying Flash has indicated the wrong Line Number that is causing the problem? It's funny because if I hadn't ticked publish debugging in the properties, the error would just say:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at Index_fla::MainTimeline/frame1()

with no indication as to which line or frame is causing the problem.

Anyway, I've inputted a code that deliberately causes an error and the line numbers match up (correct). I did this until Line 10 and the preloader error still indicates Frame 1, Line 11 (which is the var buttonsArray function). I did it after line 11 (line 12) and the error was identified as Line 12.

any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

i'm not saying flash made an error identifying the problematic line number.  i'm saying you made an error identifying the problematic line number:

stop();

works_btn.addEventListener(MouseEvent.CLICK, navigationClicked);
about_btn.addEventListener(MouseEvent.CLICK, navigationClicked);
contact_btn.addEventListener(MouseEvent.CLICK, navigationClicked);

stage.frameRate = 30;
var buttonsArray:Array = [works_btn,about_btn,contact_btn];    // <- this cannot be the problem, given the code above this line

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

Ahh! Sorry. I did it again (purpose error code), and I think the problem was:

stage.frameRate = 30;

I took it out and the error #1009  notification disappeared! Not sure how or why it just did! Maybe it's unnecessary coding?

Thanks for your help though Kglad. Much appreciated

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

if that line were in a document class, you would not see that error.  if it's in another class, you need to use the addedtostage event to ensure the stage property is available.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 24, 2011 Oct 24, 2011

Copy link to clipboard

Copied

Ahh right. Thanks Kglad!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2011 Oct 24, 2011

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines