# Loading swf + error #1009

**URL:** https://forum.kirupa.com/t/loading-swf-error-1009/262586
**Category:** flash
**Created:** [June 7, 2008, 9:22am UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586 "2008-06-07T09:22:10Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 7, 2008, 9:22am UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/1 "2008-06-07T09:22:10Z")

</div>

I am trying to load an swf, but i get this error:

```auto

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

```

all the code is in the timeline, i tried using Event.INIT and Event.COMPLETE as the event type for my Loader, I have removed all references to ‘stage’ in the loaded swf, and it plays fine when tested.  
I don’t know what’s wrong. Can someone tell me what’s wrong?

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 9, 2008, 1:12am UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/2 "2008-06-09T01:12:34Z")

</div>

I am using a movieclip in the library with linkage names… anyone?

---

<div class="post-metadata">

### Author: ![littlespex](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@littlespex](https://forum.kirupa.com/u/littlespex)
#### Post date: [June 9, 2008, 1:57am UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/3 "2008-06-09T01:57:52Z")

</div>

Can you post the code or source? That error isn’t much to go on by itself.

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 9, 2008, 2:35am UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/4 "2008-06-09T02:35:31Z")

</div>

Try waiting to run your constructor in the loader SWF until the ADDED\_TO\_STAGE event. That’s a common cause of the error.

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 11, 2008, 12:20pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/5 "2008-06-11T12:20:26Z")

</div>

here’s the code in the loaded swf.

```auto

var total:int = 4;
var count:int = 1;
var timer:Timer = new Timer(1000, total);
var boxes:Array = new Array();
var lines:Array = new Array();

var stage_width:Number = 430;
var stage_height:Number = 280;

init();

function init():void{
	createBox();
	timer.start();
	timer.addEventListener(TimerEvent.TIMER, delayedCreateBox);
	timer.addEventListener(TimerEvent.TIMER_COMPLETE, enableClickable);
}
function reset(e:KeyboardEvent):void{
	if(e.keyCode == Keyboard.SPACE){
		timer.stop();
		timer.reset();
		for(var i:int = 0; i < boxes.length; i++){
			removeChild(boxes*);
		}
		boxes = new Array();
		count = 1;
		init();
	}
}
function createBox():sbBox{
	var b:sbBox = new sbBox();
	b.percentX = Math.random();
	b.percentY = Math.random();
	b.targX = Math.random();
	b.targY = Math.random();
	b.scaleX = .01;
	b.scaleY = .01;
	b.rotation = Math.random() * 180;
	b.alpha = .2 + Math.random();
	b.x = stage_width * b.percentX;
	b.y = stage_height * b.percentY;
	
	b.addEventListener(Event.ENTER_FRAME, scaleBox);
	
	addChild(b);
	boxes.push(b);
	return b;
}
function scaleBox(e:Event):void{
	var targSize:Number = .2 + Math.random();
	e.target.scaleX += (targSize - e.target.scaleX) * .2;
	e.target.scaleY += (targSize - e.target.scaleY) * .2;
	if(e.target.scaleX >= targSize){
		e.target.removeEventListener(Event.ENTER_FRAME, scaleBox);
		e.target.addEventListener(Event.ENTER_FRAME, moveX);
		e.target.addEventListener(Event.ENTER_FRAME, moveY);
	}
}
function delayedCreateBox(e:Event):void{
	var p:sbBox = boxes[boxes.length - 1];
	for(var i:int = 0; i < count; i++){
		var b:sbBox = createBox();
	}
	count += i;
}
function moveX(e:Event):void{
	e.target.x += (e.target.targX * stage_width - e.target.x) * .1;
	if(Math.abs((e.target.targX * stage_width) - e.target.x) <= 1 ){
		e.target.targX = Math.random();
	}
															   
}
function moveY(e:Event):void{
	e.target.y += (e.target.targY * stage_height - e.target.y) * .1;
	if(Math.abs((e.target.targY * stage_height) - e.target.y) <= 1 ){
		e.target.targY = Math.random();
	}
}

function enableClickable(e:TimerEvent):void{
	
}

```

what should listen for the ADDED\_TO\_STAGE event? it’s a website, so the loader swf will need to run first before the loaded swf.  
spBox is a linkage name of a movieclip on the stage…

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 11, 2008, 5:36pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/6 "2008-06-11T17:36:23Z")

</div>

Try changing the “init()” line to reading:

```auto

addEventListener(Event.ADDED_TO_STAGE, init);

```

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 12, 2008, 2:42pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/7 "2008-06-12T14:42:38Z")

</div>

^ just tried that in the timeline code… added an e:Event = null parameter to init(), still the same error… :-/

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 12, 2008, 5:28pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/8 "2008-06-12T17:28:20Z")

</div>

Try to narrow it down to which line is causing the error, by commenting out all lines and then uncommenting blocks at a time.

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 14, 2008, 3:07am UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/9 "2008-06-14T03:07:52Z")

</div>

is it possible that the MovieClip with the linkage name is not initiated?  
because other than the class sbBox, there’s nothing in that code but numbers, functions and events…

---

<div class="post-metadata">

### Author: ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)
#### Post date: [June 15, 2008, 2:45pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/10 "2008-06-15T14:45:44Z")

</div>

just tried what was suggested in this [thread](http://www.kirupa.com/forum/showthread.php?t=301049), still the same error. :-/

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 15, 2008, 5:31pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/11 "2008-06-15T17:31:24Z")

</div>

Try commenting out lines until you find the one that is causing the error. Specifically, a good place to start is that addChild line, and anything else that might be accessing the stage. If it works perfectly when not being loaded, it’s almost always a stage access problem.

This is sort of an important debugging skill to learn - finding the source of the error by working with smaller chunks until you get it figured out.

---

<div class="post-metadata">

### Author: ![nikefido](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@nikefido](https://forum.kirupa.com/u/nikefido)
#### Post date: [June 15, 2008, 8:46pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/12 "2008-06-15T20:46:13Z")

</div>

If you can narrow down the error to a certain chunk, you can use a trace statement every other line (or however often makes sense) to see after which trace statement the code breaks down (watch your output and make each trace statement unqiue).

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [June 16, 2008, 6:04pm UTC](https://forum.kirupa.com/t/loading-swf-error-1009/262586/13 "2008-06-16T18:04:05Z")

</div>

use Debugging mode.  
Ctrl + Shift + Enter  
There you will now where is the problem
