# Loading external swf

**URL:** <https://forum.kirupa.com/t/loading-external-swf/254500>\
**Category:** Uncategorized\
**Created:** [March 12, 2008, 6:54pm UTC](https://forum.kirupa.com/t/loading-external-swf/254500 "2008-03-12T18:54:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LauraITT](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@LauraITT](https://forum.kirupa.com/u/LauraITT)\
**Post date:** [March 12, 2008, 6:54pm UTC](https://forum.kirupa.com/t/loading-external-swf/254500/1 "2008-03-12T18:54:16Z")

</div>

Hi guys,  
I really hope someone is able to help me with this problem. Its driving me crazy :jail: . Ok so here it goes. I have 4 files, InsideCastle.fla, InsideCastle.as, PointBurst.as, and IntrotogameTESTING.fla. Im trying to run IntrotogameTESTING.swf and when you click on a button I am trying to open InsideCastle.swf.

The code in InsideCastle is as follows:

> 

//import fl.accessibility.ButtonAccImpl();  
[//ButtonAccImpl.enableAccessibility](https://ButtonAccImpl.enableAccessibility)();  
import flash.net.URLRequest;  
import flash.events.\*;  
var externalSWF:URLRequest = new URLRequest(“InsideCastle.swf”);  
var myLoader:Loader = new Loader();  
Castle\_btn.addEventListener(MouseEvent.CLICK, onButtonClick);  
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, swfLoading);  
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);  
function onButtonClick(event:MouseEvent):void  
{  
myLoader.load(externalSWF);  
}  
function swfComplete(event:Event):void  
{  
addChild(myLoader);  
[//myLoader.x](https://myLoader.x) = //you can adjust the x postion here  
[//myLoader.y](https://myLoader.y) = //adjust the y position here  
}  
function swfLoading(eventprogressEvent):void  
{  
//you can do something here while the swf is loading…  
}

It throws the following error:

> TypeError: Error #1009: Cannot access a property or method of a null object reference.  
> at InsideCastle/scrollWithHero()  
> at InsideCastle/gameLoop()

The code in scrollWithHero is:

> 

public function scrollWithHero() {  
scrollWithHero != null;  
//if (scrollWithHero == null) {  
// addEventListener(Event.ADDED\_TO\_STAGE, scrollWithHero);  
// }

var stagePosition:Number = gamelevel.x+hero.mc.x;  
var rightEdge:Number = stage.stageWidth-edgeDistance;  
var leftEdge:Number = edgeDistance;  
if (stagePosition \> rightEdge) {  
gamelevel.x -= (stagePosition-rightEdge);  
if (gamelevel.x \< -(gamelevel.width-stage.stageWidth)) gamelevel.x = -(gamelevel.width-stage.stageWidth);  
}  
if (stagePosition \< leftEdge) {  
gamelevel.x += (leftEdge-stagePosition);  
if (gamelevel.x \> 0) gamelevel.x = 0;  
}  
}

And the code in gameLoop is:

> public function gameLoop(event:Event) {  
> gameLoop != null;

// get time differentce  
if (lastTime == 0) lastTime = getTimer();  
var timeDiff:int = getTimer()-lastTime;  
lastTime += timeDiff;

// only perform tasks if in play mode  
if (gameMode == “play”) {  
moveCharacter(hero,timeDiff);  
moveEnemies(timeDiff);  
checkCollisions();  
scrollWithHero();  
}  
}

You have no idea how much I need help! Im officially going mad. If you need more code to get an idea just gimme a shout!  
Thanks in advance! :beam:
