# Avoiding Error #1009 when loading external swf

**URL:** https://forum.kirupa.com/t/avoiding-error-1009-when-loading-external-swf/253915
**Category:** flash
**Created:** [March 6, 2008, 2:21pm UTC](https://forum.kirupa.com/t/avoiding-error-1009-when-loading-external-swf/253915 "2008-03-06T14:21:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![spasticfantastic](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@spasticfantastic](https://forum.kirupa.com/u/spasticfantastic)
#### Post date: [March 6, 2008, 2:21pm UTC](https://forum.kirupa.com/t/avoiding-error-1009-when-loading-external-swf/253915/1 "2008-03-06T14:21:41Z")

</div>

Hello,

I’ve often encountered this error when loading one swf into another, especially when loading papervision pv3d examples, and finally figured out why: when the loaded swf refers to stage anywhere in its startup sequence stage does not exist until that swf has been added to the stage…

The solution was to move startup code to a function and test for availability of stage…

```auto

public function Main() {
    if (stage == null) {
        addEventListener(Event.ADDED_TO_STAGE, startup);
    } else {
        startup();
    }
}

private function startup(event : Event = null) : void {
    stage.scaleMode = StageScaleMode.NO_SCALE;
    init3D();
    createCube();
    stage.quality = StageQuality.LOW;
    this.addEventListener(Event.ENTER_FRAME, loop);
}

```

Hope this helps someone.
