Skip to main content
August 22, 2011
Answered

Preloading SWF - Type Error #1009

  • August 22, 2011
  • 1 reply
  • 999 views

Hi, I was writing a preloader for an main SWF file, when I came across on the following issue:

My preloader loads main site placed in another SWF - I decided for this way because I have some fonts embedded and it should have big file size. I've done preloader, that has no problems with loading for example images. I tried with SWF and there's a problem:

mainsite.fla - there's only blue rectangle named "square" that is fluid. Here's the code:

stop();


stage.frameRate = 30;

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.align = StageAlign.TOP_LEFT;


stage.addEventListener(Event.RESIZE, onStageResize);


function onStageResize(evt:Event):void {

     square.width = stage.stageWidth;

     square.height = stage.stageHeight/2;

}

Of course it's mistakes-free, works as I want.

But when I load it into another SWF, there's a error: TypeError: Error #1009: Cannot access a property or method of a null object reference at mainsite_fla::MainTimeline/frame1() in my language.

I loads it with standard Loader and URLRequest class, but do not try to get acces to this SWF file, just loads it and it's enough for Flash to show that error.

Can anybody explain me why it's going this way? It's a freelance work, so I have to finish this rather quickly.

This topic has been closed for replies.
Correct answer Ned Murphy

Try removing any stage-based code from the loaded file and see if it loads without an error.  As far as I understand it, the loaded file has no stage... the file that loads it does.

1 reply

Ned Murphy
Legend
August 22, 2011

Try tracing the stage in the file that gets loaded.

August 22, 2011

I've put trace two times - at the beginning and the end of the code. Console output:

> preloader.Main start

Start loading file.

Stage: null

TypeError: Error #1009: Nie można uzyskać dostępu do właściwości lub metody dla odniesienia do obiektu null.

at mainsite_fla::MainTimeline/frame1()

[object LoaderInfo]

Error is the same as above, but in Polish. There's an error and mainsite stops, otherwise there would be one "Stage:" more.

Can you also tell me why mainsite code is executed when loading stops?

Ned Murphy
Ned MurphyCorrect answer
Legend
August 22, 2011

Try removing any stage-based code from the loaded file and see if it loads without an error.  As far as I understand it, the loaded file has no stage... the file that loads it does.