Skip to main content
Participating Frequently
July 7, 2011
Question

#1009: Cannot access a property or method of a null object reference.

  • July 7, 2011
  • 1 reply
  • 564 views

I have been trying to solve this on my own but have not been succcessful as of yet so I am reaching out hoping for help.

I have a full screen flash video slideshow homepage.  the preloader is on frame 1 the first slide is on frame 2, the second slide is on frame 3 and so on.

The actionscript on frame 1 first states NO_SCALE,

then aligns the stage to top left,

then sets the width of the asset with regard to the width of the stage,

then creates the aspect ratio var

then sets the scaleY based on the ratio.

Here is where I get errors:

I have an event listener with a resize trigger.

When the stage is resized a function is called that changes the dimensions of the asset (same formula as before)

However when I resize the stage after "Test Movie" IDE reports errors:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at homepage_fla::MainTimeline/onStageResize()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at homepage_fla::MainTimeline/onStageResize2()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at homepage_fla::MainTimeline/onStageResize3()

The functions mentioned in the errors are the specific functions for each slide so here the first second and third slides threw an error on resize.

I have seperate functions in the actions of each slide frame but am only calling the noscale and alignstage in the second frame.

I do not seee extra code that may be fouling the code indicated here though I guess that could be possible, but the only other code (slideshow AS) works sans errors without the resize code.

CODE IN FRAME 1

// Set stage to no scale
stage.scaleMode = StageScaleMode.NO_SCALE;
//Align To Top Left
stage.align = StageAlign.TOP_LEFT;
mc_Asset1.scaleX = stage.stageWidth/1920;
var ratio = 4/3;
mc_Asset1.scaleY = (stage.stageWidth/1920) * ratio;
stage.addEventListener(Event.RESIZE, onStageResize);
function onStageResize(evt:Event):void {
    mc_Asset1.scaleX = stage.stageWidth/1920;
    mc_Asset1.scaleY = (stage.stageWidth/1920) * ratio;
}

wait(7);

...slide show AS below...

CODE IN FRAME 2

mc_Asset2.scaleX = stage.stageWidth/1920;
mc_Asset2.scaleY = (stage.stageWidth/1920) * ratio;

stage.addEventListener(Event.RESIZE, onStageResize2);
function onStageResize2(evt:Event):void {
    mc_Asset2.scaleX = stage.stageWidth/1920;
    mc_Asset2.scaleY = (stage.stageWidth/1920) * ratio;
}
wait(7);

...slide show AS below...

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
July 7, 2011

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....


 
- is not in the display list
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
 
If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.
dondmcgAuthor
Participating Frequently
July 7, 2011

"does not exist in the frame where that code is trying to talk to it"

this sounds like it because if I resize the stage when the first slide is onscreen the second time then I get errors for all other four slide functions.

It appears that after the slide show runs through once all the functions that ran are in memory or something and all try to fire when the stage is resized.

Can I clear the functions after they run so they are not called when resizing a different slide (different frame) and how do I handle instances when I start resizing on one frame (slide) and stop on a different one?

dondmcgAuthor
Participating Frequently
July 7, 2011

debugging says the error is on this line:

mc_Asset1.scaleX = stage.stageWidth/1920;

which would be the first instance (mc_Asset1) in the code of the movie clip asset that is no longer available because we are on a different frame.