# Calling Function from Externally Loaded SWF into Main SWF

**URL:** <https://forum.kirupa.com/t/calling-function-from-externally-loaded-swf-into-main-swf/285712>\
**Category:** flash\
**Created:** [April 4, 2009, 4:15pm UTC](https://forum.kirupa.com/t/calling-function-from-externally-loaded-swf-into-main-swf/285712 "2009-04-04T16:15:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wingwu](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@wingwu](https://forum.kirupa.com/u/wingwu)\
**Post date:** [April 4, 2009, 4:15pm UTC](https://forum.kirupa.com/t/calling-function-from-externally-loaded-swf-into-main-swf/285712/1 "2009-04-04T16:15:26Z")

</div>

I’m new to Actionscript 3.0. Help?

I’ve written a script that takes keyboard input to turn movieclips on and off in a swf file (like the visible/invisible layer function in photoshop). Then I’m attempting to load the \*.swf (image.swf) into a [zoom/pan flash file](http://www.flashden.net/item/zoom-pan-controls-with-dynamic-image-settings/15713?page=11) from flash den. When I load it in, the keyboard controls no longer work.

I’ve tried importing the keyboard control function (keyDownListener) into the main zoom.fla with this script:

```auto
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;

var loader:Loader;
var req:URLRequest;
var loadedSWF:Object;
loader = new Loader();
addChild(loader);
            
req = new URLRequest("image.swf");
loader.load(req);

// check when we're done loading        
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
	

function initHandler(e:Event):void {
	
    loadedSWF= loader.content;
   
	loadedSWF.keyDownListener();
	  
}

```

It returns the errors:  
ArgumentError: Error #1063: Argument count mismatch on image\_fla::MainTimeline/keyDownListener(). Expected 1, got 0.  
at zoom\_fla::MainTimeline/initHandler()  
TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at image\_fla::MainTimeline/frame1()

And if it helps, this is the script I have running on the image.fla file:

```auto
import flash.events.KeyboardEvent;

//keycodes
var one:uint = 49;
var two:uint = 50;
var three:uint = 51;
var four:uint = 52;
var five:uint = 53;
var six:uint = 54;
var seven:uint = 55;
var eight:uint = 56;
var nine:uint = 57;
var lightenON:uint = 76;
var darkenON:uint = 68;
var lightdarkON:uint = 65;
var bringforward:uint = 70;

stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);

function keyDownListener(e:KeyboardEvent) {

		
if (e.keyCode==one){
		
		if (parcel13d.alpha==0){
			
			parcel13d.alpha = 1;
			parcel13l.alpha = 1;
		} else {
		parcel13d.alpha= 0;
		parcel13l.alpha= 0;
		
		}
	}

```
